March 23, 2015
Fortunately, Google Tag Manager has some fantastic built-in features to make doing this a snap, and you may not even realize that it’s already implemented on your site!
What’s an Iframe?
An iframe is kind of like a popup, but embedded in the page. They are used for lots of things, like web analytics, ad targeting, and embedded 3rd party content.
Google Tag Manager’s installation instructions include an iframe that you by default include on your site. It’s one of the reasons that GTM is added in the BODY of your site, and not the HEAD.
How It Works
A Simple Example
Setting our Firing Trigger to All Pages will tell Google Tag Manager add this tag to every page, resulting in a request for pixel.gif?key=noscript-pageview on each pageview, which our server would in turn interpret as a hit and increment our counter for us.
That’s where the data layer comes in.
Query parameters are key-value pairs of text that appear after the ? in a URL, paired by equals symbols (=) and separated by ampersands(&). They are used by web applications and web servers in order to modify the content that the server sends back to our browser.
height="0" width="0" style="display:none;visibility:hidden"></iframe>
Then set up a Data Layer Variable like this:
Added the Variable to the Custom Image Tag:
Using this, we can create a Trigger that fires our tag only when the user isn’t executing scripts.
// Variable Noscript
Using Dynamic Data Layer Values
We can also make our data layer variables dynamic by changing the value in our key-value pair in the code on our server. This requires some server-side logic, where you’re either pulling information from a cookie or generating the information yourself. This really opens up what we can track with this feature.
An Advanced Example
The UA Number of the account we’re sending the hit to
The version number of the protocol we want to use (currently only version 1 is available)
The hit type (pageview, event, etc)
The full URL of the page we’d like to say a pageview has occurred on
A user identifier used to group hits into sessions
The tid, v, and t parameters all have static values, but the cid and dl values are dynamic. We can populate these values dynamically on our server:
Side Note:If you can’t populate your cid dynamically, use the built-in Random Number Variable instead; this Variable will still work. If you use a static number, all your hits will be associated with one user, and since Google Analytics stops processing hits for users after they’ve sent 200,000 hits in a day, you could accidentally hit this limit and stop recording data. You can also try and come up with a user-specific value; this example would create a new user every session.
We could do the same for our dl value, but Google Tag Manager makes it easy for us: enabled built-in Variables are accessible when the page loads, including the Page Variables like Page URL and Page Path. Google Tag Manager populates these by parsing the referrer when the browser requests the iframe content (thanks guys!). We can use the built-in Page URL variable for our dl value:
Our v and t values (API version and hit type) won’t change, so we can add those in statically.
Finally, we can use the same ‘Noscript Is True’ Trigger to fire our pageview.
And there you have it; you’re tracking Pageviews from browsers that don’t execute scripts.