简体   繁体   中英

Send pageview to virtual URL with google tag manager to google analytics

With the new Google Tags Manager,

I've tried setting up "on button click with class contains x" : "pageview x" that didn't work

I've tried setting up "on button click with text contains x" : "pageview x" that didn't work

tried to add a virtual page view programmatically:

window.dataLayer = window.dataLayer || []; window.dataLayer.push({
 'event': 'Pageview',
 'pagePath': '/test',
 'pageTitle': 'Test'
});

didn't work,

Tried:

ga('send', 'pageview', '/test');

Didn't work either,

Other pages are being tracked successfully as I see them in the Real Time Viewer in google analytics...

Please help sending a virtual URL for ajax url states to google analytics...

You need to generate an event in Google Tag Manager, very similarly as you have already tried with dataLayer.push

This would be a very basic example for a similar function, which you can use as a callback, providing the path and title variables.

function generateVirtualPageView(path, title) {
  window.dataLayer.push({
    event : 'virtualPageView',  //fixed value you need to use as trigger in GTM
    virtualPagePath : path,
    virtualPageTitle: title
  });
}

In GTM, you need to create an Event type trigger, where event name is matching the one in your dataLayer.push. In my example: virtualPageView

You need to create two data layer variables, referencing the page and title values in the dataLayer push, set in the "Data Layer Variable Name" setting of the variables. (virtualPagePath and virtualPageTitle in my example)

You can now create an Universal Analytics tag, which sends a Pageview as hit type, triggered by your newly created custom event, and referencing your variables within the Fields to set block, where Field names are page and title , which need to be set to the variables created.

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