简体   繁体   中英

What is the analytics.js equivalent of _trackPageview found in ga.js

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?

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'
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM