How do I track Virtual Pageviews in the new version of GTM? - google-analytics

I've attempted to use the new version of Google Tag Manager to track virtual pageviews and send those to Google Analytics, but they don't seem to be sending properly.
For my Trigger, I've used the builtin History Change event type and have placed that in a tag with my Google Analytics id. The tag is set to Page View track type.
In Google Analytics, I see a pageview, but it just says the user is on the root directory. Also, I'm working in Localhost.
Is there something I missed?

I'm not sure to get the complete description of your setup but maybe an other way of tracking your virtual pageview could be directly by adding data layers directly in your code.
dataLayer.push({
'event':'VirtualPageview',
'virtualPageURL':'/order/step1',
'virtualPageTitle' : 'Order Step 1 – Contact Information'
});
For the trigger, you will then be able to send the fire on of your virtual pageview as a event matches VirtualPageview.
Your Tag need to be set up as a pageview.
Also, using this article for GTM v1 : http://www.lunametrics.com/blog/2014/09/10/fire-virtual-pageview-google-tag-manager/, you can set up your {{virtualPageURL}}
In GTM V2, in your tag, you will have to use the - More settings / Field to set field Name = Page, Value = {{virtualPageURL}}.
Are we talking here about a one page iOS/Android App?

Related

Execute Google Analytics Functions in addition to Google Tag Manager

When using the Google Tag Manager, is it possible to track some things the old way in addition to using the GTM?
For example, I use GTM in order to fire a page view.
However, I want to fire another page view, when a user clicks a button, also known as a virtual page view.
The button in question doesn't have an ID and I don't trust the othet agency, which handles these buttons to consistently keep the same IDs for these elements. So I would rather have them be responsible for these types of page views.
The code for the virtual page view would look something like that:
ga('send', {
hitType: 'pageview',
page: 'button2'
});
Since the tracker is already initialized by GTM, I would only have this code outside GTM.
Would this work if all other google analytics related things run over gtm and where should I put this code in this case? Somewhere after the GTM code on the page I'd imagine?
Google Tag Manager (GTM) by default uses a random name for each tracker, generated for each Universal Analytics tag. There is a possibility to use fixed name for trackers, which is highly discouraged. This means, that you might have difficulties to identify the proper tracker to use, when sending your additional pageview data.
There are however other methods to send virtual pageviews using GTM, where you can benefit from your existing Analytics settings, defined in Google Tag Manager. (Preferably by using Google Analyitcs Settings variable.)
As far as I understand, you have control over the code, to run some JavaScript on the relevant click event.
So instead of directly invoking the ga object, you can send the desired data to GTM, with a call like this:
dataLayer.push({
event : 'virtualPageView',
virtualPagePath : 'button2'
});
Obviously, there are a couple of things you need to set up in GTM, which will be able to act on this event, and send the pageview to Google Analytics.
Create a variable that points to virtualPagePath dataLayer variable, so the newly pushed value could be reused
Create a custom event trigger, that can be used with one or more tags. The event name should match your given event name, virtualPageView in my example.
You need an Universal Analytics tag, which will send the pageview. This tag should be fired by your new custom event trigger, and should have an extra setting compared to your regular pageview tag. Namely, page variable within the Fields to set block should point to the newly created dataLayer variable, that contains your virtual page path.
This way, Google Tag Manager will take care of creating the tracker for you, sending the hit to Google Analytics, and using the virtual page path variable provided by you, instead of the URL in the browser address bar.

Google Tag Manager (GTM) virtual pageview doesn't show in Google Analytics (GA)

I've created a GA tag in GTM. It has "Enable overriding" checked. The Field Name is the Page Path built-in variable, and the value is "/register".
So the goal is for this tag to send a virtual pageview when triggered to GA with the page path value of "/register".
I can see the tag is triggered on the website at registration in debug view. However, I do not see any pageviews in GA with the name of "/register".
I've read every guide I can find, but can't figure out what to try next to get this to work..
You are setting the wrong value for Field Name. If you change {{Page Path}} to page that will start sending virtual pageviews.
You are doing 2 mistakes.
The right field to set is page and not {{Page Path}}
When you are selecting "override" make sure to put the UA ID
directly on the field, OR make a new constant variable maybe by name
"GA UA ID" put your GA ID over there and than select that variable
under override tracking id field. You are selecting the same GA
settings variable that is causing the issue if you still not seeing
after updating the field settings

Funnel Setup in Google Analytic through Virtual pageview tag in GTM

I need help in creating a Goal with funnel into a Google Analytics for New Registrations using virtual pageview tag on GTM.
I am not sure what trigger should be use for this tag? Tag is here:
Can anyone help/guide me to setup a trigger?
You will need to push your own custom event on the dataLayer every time a "virtual" page is shown. You could do this as follows:
dataLayer.push({'event' : 'virtualPageview', 'virtualPageName' : 'virtual/registration/complete'});
You would then create a GTM trigger of type Custom Event and the name of the event would be virtualPageview. This will cause your Google Analytics page view tracking tag to fire every time a virtual page is shown. You would also need to pass the value of the virtualName dataLayer key to the GA page view tag. You can do this using the "Fields to Set" section of the tag configuration as follows:
. The Virtual Page Name variable would be defined as follows:
Then, when defining your goal funnel in Google Analytics, you would enter some/virtual/page/name as the funnel step as follows:

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
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 :
Go to the tag that handles your GA "page views"
In "More settings", look for "Fields to set"
In the field name, pick {{url}}
For the value, you should create a macro that gets your "url" from the data layer:
As I understand, you can use basic virtual page view behavior by creating GA tag with rewrited url. This tag will be fired, when two events will happen - one for every page view that you want to track. You will only need to add two pushes to dataLayer for events - event itself and dataLayer veritable with url. For example, it can be something like that: dataLayer.push ({'event':'first-event','custom-url':'/my/custom/url1'}).
In GTM you should create a macro, that gets the value of 'custom-url' dataLayer veritable, and use it to rewrite url in your GA tag.

How to call _trackPageView from Google Tag Manager for an AJAX page?

I have a page loaded in via AJAX.
In Google Analytics I could have just called gaq.push('_trackPageView','/someurl') in my AJAX success function. However I can't seem to find a way to do this when implementing GA via Google Tag Manager.
The only alternative seems to be a "virtual page view" event, which isn't exactly what I'm after:
Does anyone know how to do this?
on the Ajax success, do:
dataLayer.push({
'event':'sendVirtualPageview',
'vpv':'/blah/blah'
});
The 'event' is just to send the virtual pageview to GTM. It's not a traditional, although it could be, Google Analytics event.
You should be able to folllow the rest of the tutorial to create your rule and setup the tag type.
Here's how you enable Virtual Page Views on your Google Analytics tag in GTM.
GTM v2:
Go to the Variables page. Enable the Event variable {{event}} by ticking the Event checkbox inside Utilities under the Enable Built-in Variables heading.
Create a variable named Virtual Url with type Data Layer Variable and set the Data Layer Variable Name to "virtualUrl".
Go to the Triggers page. Create a trigger named Virtual Page View with type Custom Event and set the Event name to "virtualPageView".
Create a tag GA Virtual Page Views with product Google Analytics Universal. Set your Tracking ID UA-xxxxxx-xx. Set the track type to Pageview.
Under More Settings > Fields to set, click + Add Field.
Set Field Name to page with value {{Virtual Url}}.
You can add additional fields here, such as title, UTM campaign etc. Add variables then add them here.
Click Continue. Under Fire On, click More. In the triggers popup, tick Virtual Page View. Click Save.
Click Create Tag.
GTM v1:
Create a macro {{Virtual Url]} referring to dataLayer variable "virtualUrl".
Create a {{Virtual Page View}} rule as {{event}} equals "virtualPageView".
You should already have an {{event}} macro, but if you don't, create one using the dataLayer variable "event".
Updates to your Google Analytics tag:
More Settings > Basic Config, tick "Virtual Page Path" and use macro {{Virtual URL}}.
Remove the {{All Pages}} firing rule.
Add the {{Virtual Page View}} firing rule.
GA Fields:
page = the path portion of a URI. eg. /blog/topic/post.html
title = used to specify the <title> contents
campaignMedium = used to specify the URI utm_medium
campaignSource = used to specify the URI utm_source
campaignTerm = used to specify the URI utm_term
campaignContent = used to specify the URI utm_content
campaignName = used to specify the URI utm_campaign
Usage:
In your web app, call it like so:
dataLayer.push({
'event': 'virtualPageView',
'virtualUrl': '/relative/page/path',
'virtualTitle': 'My page title'
});
You can rename any of the variables above - this is just an example based on how we do it.

Resources