Google Tag Manager and Single Page apps

后端 未结 2 1972
刺人心
刺人心 2021-02-01 19:50

I\'m trying to integrate Google Tag Manager with my Ember app. I\'m having a hard time understanding how to notify GTM that the page changed, and send a page view event.

2条回答
  •  别那么骄傲
    2021-02-01 20:06

    You definitely need to push events into the dataLayer which you can then trigger a GA page view tag in GTM. So to push an event into the DL:

    dataLayer.push({'event':'virtualPageView'});
    

    Then setup a trigger called 'vpv' which fires on a custom event called 'virtualPageView'. Add that trigger to a GA tag.

    The best thing to do is also send through the details of the virtual page when you send the event. This way you can set up variables that pull these dataLayer property values into the page view call. So you might do this:

    dataLayer.push({
      'event':'virtualPageView',
      'page':{
        'title':'contact us',
        'url':'/contact'
      }
    });
    

    So you'd setup a variable called 'DL- page title' (for example) which is a dataLayer value of 'page.title' and another variable called 'DL - page url' which is a dataLayer value of 'page.url'.

    You then setup a new Universal Analytics tag which has all your usual pageview settings but with 2 'Fields to Set' (under More Settings). Set 'title' to {{DL-page title}} and 'page' to {{DL - page url}}

    Finally set the trigger to 'vpv' and you'll find everytime you push the event + data into the datalayer you'll get a pageView fired off with your virtual page's title and virtual url.

提交回复
热议问题