Sign in to follow this  

Journal tracking with Google Analytics

This topic is 1891 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it somehow possible to include a small piece of javascript on the journal page / posts to track views with analytics? It would be useful to gather some data. Or a function to just add the tracking code, since actually submitting a pageview request to analytics is really simple.


[source lang="jscript"]
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', tracking_id]);
_gaq.push(['_trackPageview']);
(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);
})();
</script>[/source]

Share this post


Link to post
Share on other sites
Yes, that's possible through asynchronous tracking code!

[url="https://developers.google.com/analytics/devguides/collection/gajs/?hl=pl#MultipleCommands"]https://developers.g...ultipleCommands[/url]

[source lang="jscript"]
_gaq.push(
['_setAccount', 'UA-XXXXX-X'],
['_setDomainName', 'example.com'],
['_setCustomVar', 1, 'Section', 'Life &amp; Style', 3],
['_trackPageview']
);

[/source]

On the second example you can see that you can even push views for multiple trackers on the same command.

[source lang="jscript"]
_gaq.push(
['_setAccount', 'UA-XXXXX-1'],
['_trackPageview'],
['b._setAccount', 'UA-XXXXX-2'],
['b._trackPageview']
);

[/source]

I'm not sure if there's enough demand for this to be done, but it would be sweet for those interested on the data! Edited by Arthur Souza

Share this post


Link to post
Share on other sites
Sign in to follow this