David Leal
David Leal

Posted on: November 13, 2014

In: Data


Has this ever happened to you, or one of your clients:

You have a website with tons of content.

Visitors are consuming that content and actually converting. (Great!)

Only problem is, the conversions occur on a third party site, so you aren’t sure where these visitors are coming from.

The problem

Normally, this wouldn’t be too much of a problem. Universal Analytics and GTM makes it fairly simple to track users seamlessly across domains. Usually the relationship between domains is simple. Click, boom, you’re there.

However, sometimes there is some sort of interstitial page, such as a redirect or login that does not have tracking on it. This prevents Universal Analytics from linking visitors between the two different domains. Looking at reports, we will see one visitor on source.com and a different visitor on destination.com. This means that when we look at conversion counts, we won’t know for sure where the converting visitors are coming from (they will likely be tracked as Direct) or be able to connect activity on the source site in any meaningful way.

But fear not analytics heroes, we can stitch these visitors together with help from our old nemesis the iframe. That’s right folks, the notoriously difficult-to-track iframe can illuminate and close analytics black holes on third party websites.

The solution

Startlingly simple, the solution is to open a hidden iframe on the third party site that points to a page on your domain. The page that the iframe opens up to then sends a virtual pageview, as if the page on destination.com were on your site.

The approach requires:

  • GTM on pages you want to track
  • jQuery (Straight JavaScript will work too, but the code is simpler in jQuery)

Here is how you do that step by step:

1. Open up the iframe on the third party site with this script. It goes in a Custom HTML Tag in GTM and the rule to fire it would be any page on the third party website.


var src = “//www.source.com/?vpv=” + {{url path}};

jQuery(‘<iframe hidden id=”ga-linker”>’).appendTo(‘body’);

jQuery(‘#ga-linker’).attr(‘src’, src);


2. Create a macro with Macro Type of URL, Component Type of Query and Query Key of “vpv”. We will call this macro Virtual Page.

cross domain tracking 1

Create a macro.

3. Create a rule that fires when the URL contains “?vpv=”. We will call this rule “Fire Third Party Tracking.”

cross domain tracking 2

Add rules.

4. Create a UA pageview tag with all the settings you would normally have, except for Document Path. For this we want to use our new macro {{Virtual Page}} and a virtual file path that makes the virtual pages easy to distinguish. We will use /virtual-pages/{{Virtual Page}}

cross domain tracking 3

Create a tag.

Now you will be tracking pageviews on the third party site as virtual pages on your own site.

The conclusion

This is one of my favorite tricks to use with Google Tag Manager. With three lines of JavaScript code, GTM can shed light on that 3rd party black hole. Not only can you see what visitors are doing, but you can connect them back to their behavior on your website.

This method can even be extended to track events. All you have to do is trigger an event instead of a pageview, and use more query string parameters to pass along the categories, actions and labels. Nifty!

Recent Posts

Upcoming Events

CHIFOO Meetup: March

March 4 @ 5:30 pm - 8:00 pm PST


Ready to make your next project the first step in delighting your customers and growing your business? Let’s talk!