Connective DX

DATA Cross-domain tracking for third-party sites

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.

<script>

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

jQuery('<iframe hidden id="ga-linker">').appendTo('body');

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

</script>

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.

Create macro
Create a macro.

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

Add Rules
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}}

Create Tag
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!

Related Thinking

Sitecore Engagement Analytics for objective-based decision making

We explore how Engagement Analytics can show the value and marketing effectiveness of efforts over time.

Full Article