Reputation: 8233
Using the previous version of google analytics (ga.js) you can track a virtual page view using the _trackPageview method to record when something is downloaded or some other metric if desired. Using the new analytics.js what is the syntax to track a virtual page view?
Upvotes: 3
Views: 2070
Reputation: 4789
Just as you use the standard _trackPageview method for ga.js, in analytics.js also you can track virtual pageview by using the standard function.
Assume you have arleady initialised your analytics tracking code as below:
function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-X', 'name as seen in GA tracking code');
Now inside any function block in your page, where you want to track a virtual page view , call the send pageview with the suitable name and title you want for the virtual page:
ga('send', 'pageview', {
'page': '/usersignup',
'title': 'user signup'
});
Upvotes: 4