(888) 328-8667 [email protected]

When using the vanilla Google Analytics (GA) tracking code, clickthroughs on overlays or embedded boards/cards hosted on a secondary domain (e.g., tribl.io) will generate a new session within GA, rather than continuing a previous session. You can get around this by adding a slightly modified GA tracking code on both your main site and the iFrame content as to support “cross-domain tracking”. This allows the original GA session to continue, and preserves the original source of the visitor (e.g., Search, Social).

If you want to preserve the session and source information for a visitor who clicks on iFrames, install your GA tracking code as instructed below. You will need admin access to your Google Analytics and the two domains which you will deploy your GA code on (or access to edit and publish Google Tag Manager containers for these domains.) For this example, we’ll assume you are using Triblio content boards/cards, but a similar approach can work with marketing automation landing pages or other applications you might embed in iFrames.

Note: If you use a WordPress plugin that activates your GA automatically, it probably doesn’t allow cross-domain tracking. You’ll need to manually place the GA tracking code in your header file, add it to a global header plugin/theme option, or use Google Tag Manager.

1. Login to your website’s GA dashboard, navigate to the Admin tab, and then click “Tracking Info”… “Tracking Code”.

 

tracking info

 

2. Copy paste the tracking code on the next screen (it’ll look like the below) into your favorite plain text/code editor. We will be changing only the bolded line:

<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-1', 'auto');
ga('send', 'pageview');</script>

3. For your main website domain, change this line…

ga('create', 'UA-XXXXXXXX-1', 'auto');

…to look like this:

ga('create', 'UA-XXXXXXX-1', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', [‘tribl.io'] );

(Replace tribl.io with any secondary domain you are embedding/overlaying via iFrames.)
Save/publish this modified tracking code on your main site.  This edit tells GA that you are linking your domain with another domain (and what that domain is). Your new code will look like this:

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXX-1', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', [‘tribl.io'] );
ga('send', 'pageview');
</script>

4. You now need to embed a very similar block in the header of your iFrames you wish to count as part of a session on your main website. This time, put the main domain name you are linking your iFrames to on the “autoLink” line.

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXX-1', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', [‘maindomain.com’] );
ga('send', 'pageview');
</script>

5. You can add this script block to dynamic boards in Triblio by navigating to the “Custom Header” window in the “Style” tab under “Advanced Settings.”

triblio_header

Note: the GA Integration buttons appearing in the hub settings pages do not yet support cross-domain tracking.
Save your changes. Your pages should now be linked! Now if someone comes through to your site from Google and Twitter, and clicks on an overlay or popup (but stays on your same site), their session will not be split, and you’ll preserve their original referrer source/medium.

Questions? Comments? Let us know in the comments below!

Bonus: If you want to link your main site to multiple other domains, you can do this by making these lines…

ga('linker:autoLink', [‘tribl.io’] );
ga('linker:autoLink', [‘maindomain.com’] );

…look like this:

ga('linker:autoLink', [‘tribl.io’,’domain2.com’] );
ga('linker:autoLink', [‘maindomain.com’, ‘domain2.com’] );