Search code examples
google-tag-manageruniversal-analytics

gtm tag manager virtual pageview (URL rewrite)


Current tracking of the checkout funnels is done through Pageview using virtual pageviews via

_gaq.push(['_trackPageview', '/checkout/login']);

_gaq.push(['_trackPageview', '/checkout/address']);

which has been hardcode into the webpage.

We are now updating to UA through GTM with enhanced Eccomerce. I would still like to continue to track the checkout funnels with the current method while implementing the Enhanced Eccomerce step 1 / step 2 codes.

My question is If i can fire a datalayer push to overwrite the url which the {{url path}} macro in GTM will track so instead of using /pws/secure/CheckOut.ice?&checkout=true&secure_from=checkout as a goal URL I can use the virtual urls "/checkout/login" and "/checkout/address".

*for some reason only the login and address pages of the checkout are on the same URL.

Would something like this work

dataLayer.push({
'url path':'/blah/blah'
});

If not is there a way I can use the lookup macros in GTM to do Document Path = {{Virtual URL}} (IF it not empty) or {{url path}}. Basically I dont want to have to create multiple tracking codes for each of the checkout funnels with the virtualURL in the Document path. Not to mention how I would get GTM to recongise that one second the URL is a login page and the next it an address page.

Any ideas would be really appreciated


Solution

  • That's correct, you can use the data layer to push your own URL path to Google Tag manager. First you need to set the path in the data layer as you mentioned.

    dataLayer.push({ 'url':'/foo/bar' });

    Then, in Google Tag Manager, you can do the following :

    1. Go to the tag that handles your GA "page views"
    2. In "More settings", look for "Fields to set"
    3. In the field name, pick {{url}}
    4. For the value, you should create a macro that gets your "url" from the data layer:

    url in universal analytics page view

    enter image description here