Event tracking not working

2019-07-17 02:05发布

问题:

I am trying to integrate the Google's event tracking on my application using the below script. I can able to see the Events in "Realtime" tab. But I am not able to see the events in "Content" tab.

  var _gaq = _gaq || [];
  _gaq.push(['_setDomainName', 'none']);
  _gaq.push(['_setAccount', 'XXXXX']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_trackEvent', 'request.fullpath', 'plan_desc', 'plan_code>']);

回答1:

Are you grabbing the script that defines the gaq function?

var _gaq = _gaq || [];
  _gaq.push(['_setDomainName', 'none']);
  _gaq.push(['_setAccount', 'XXXXX']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_trackEvent', 'request.fullpath', 'plan_desc', 'plan_code>']);
(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

Also, for your event push, are the values you are pushing in supposed to be JS objects? if so, you may want to get rid of the quotation marks.



回答2:

GA takes a certain amount of time before it translates data that you see in real-time into it's other sections.

It might be that if you have only added the code within 48 hours that results are not ready to view yet.



回答3:

I would suggest you trying Google Analytics Debugger extension for Chrome to see if tracking events reach google.

https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna?hl=en



回答4:

If you are trying to use Rails variables in the JS, as request.fullpath looks like one you must make sure you are rendering it out in your templating engine. For example, if you are using ERB, you must call it like this...

_gaq.push(['_trackEvent', '<%= request.fullpath %>', 'plan_desc', 'plan_code>']);

Obviously repeat for the other variables, if they aren't Ruby and are plain JS objects, you need to omit the quote marks around them.