Outsmarting Google Analytics To Record iFrame Conversions From Adwords Data

John Bialous November 3, 2014

Every digital marketing professional knows how important it is to have access to conversion tracking data.  It shows the effectiveness of marketing efforts, and is key in setting and monitoring goals, especially when paid search is involved.

But what happens when the right data isn’t being sent from Google Adwords to Google Analytics and marketing is essentially ‘flying blind’?

In this post, Joe Zeoli, Senior Website and Graphic Designer at Miles Technologies shows you how to outsmart the big G when it comes to multi domain conversions across iFrames, to get access to all the right numbers.
The Scenario:

You decide to use a third party to manage the leads you get with your contact form . To do that, you have to use an iFrame that contains a form. When submitted, that iFrame changes URLs to the “thank you” message, but the user stays on the same page on the parent site. You have put money into your Google Adwords account and you want to still be able to tell where users are converting from.

The following diagram shows the scenario, with example1.com being the webpage and example2.com being the iFrame:

The Problem:

In Google Analytics, referral source is tracked via cookies in the user’s browser. When a user clicks on one of the ads, that information gets stored in a cookie. When a conversion gets triggered in Analytics, it is able to tell where that user came from.

This works really well on a normal site, but for security reasons, you cannot access another domain’s cookie information. In this scenario, the third-party iFrame presents a problem because the URL contained in the iFrame is different than the main site (see image below).


If Analytics and Adwords conversion tracking are implemented on both domains, you will see conversions, but all of them will be from ‘direct’ traffic sources in Analytics.

Google offers a way to track between two different domains in their API, however it is very difficult to implement, and in this scenario the cookie data was not saving in the second domain.


The Solution:

When you first click on an Adwords ad, you will notice it takes you to one of your pages, but with some extra parameters in the URL. So if your landing page was www.example1.com, after clicking an ad, it will take you to www.example1.com?gclid=fn4398fnp4n9fa. That ‘gclid string’ is gibberish to us, but it contains all of the important Adwords information that Google needs.

The conversion code on the site sees this string and instantly saves this information as a cookie. Now you can browse the website without that extra parameter in the string and Analytics will still be able to attribute a conversion to Adwords.

The solution to this problem is to trick the conversion code on that second domain into thinking that the user came from an Adwords ad and landed there so that the cookie also gets stored in that domain.
To do this we have to first get the information stored in the cookie (Google stores referral information in __utmz). Next we have to take that information and pull out the gclid if it exists. Lastly we append that to the second domain’s URL and produce the iFrame.


Here’s an example of code you could use to implement the solution:

//This Function Gets The Value of the Cookie
function getCookie(cname) {
   var name = cname + “=”;
   var ca = document.cookie.split(‘;’);
   for(var i=0; i<ca.length; i++) {
       var c = ca[i];
       while (c.charAt(0)==’ ‘) c = c.substring(1);
       if (c.indexOf(name) != -1) return c.substring(name.length,c.length);
   return “”;
//This Function Gets The Value of the Adwords String
var utmz = getCookie(‘__utmz’);
var value = (function() {
       var pairs = utmz.split(‘.’).slice(4).join(‘.’).split(‘|’);
       var ga = {};
       for (var i = 0; i < pairs.length; i++) {
           var tmp = pairs[i].split(‘=’);
               ga[tmp[0]] = tmp[1];
       return ga;


This code will produce an object and you can see if value.utmgclid exists. If it does, you can add that to the end of your iFrame URL and place it on the DOM. This will trick the iFrame into saving that information as a cookie and your conversion will be tracked properly:


var iframe = document.getElementById(iFrameID);
   iframe.src = ‘http://www.example2.com?gclid=’ + value.utmgclid;              
} else {
    iframe.src = ‘http://www.example2.com’


Zeoli’s solution is just one example of ‘out of the box’ thinking found at Miles Technologies.  Do you have any other examples of workarounds?  Let us know in the comments below. 

If you need help with your website or marketing, feel free to contact us today.

Leave Us a Comment

Your email address will not be published. Required fields are marked *

Do great things.

Get Started