AdWords
6.5K members online now
6.5K members online now
Use AdWords conversion tracking and reporting to measure your results. Have a question about Google Analytics? Post it here, on the Google Analytics Community!
Guide Me
star_border
Reply

Tracking Salesforce conversions using form in iframe

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi, I'm attempting to track our offline Salesforce conversions in Adwords. I'm following this guide: https://support.google.com/adwords/answer/6299296.

Now it does say that the web-to-lead form should be on the same domain as the site, but in our case it isn't, it's in an iframe on another domain that we control. Can anyone recommend a way to pass the GCLID to the iframe? I've attempted to use the postmessage function (which allows cross domain communication) but my Javascript is limited. Is it possible?

 

Our Analytics tracking code is on both domains and cross domain tracking is enabled, but I don't believe this applies to reading a cookie to get the GCLID from one site to the other. Correct me if I'm wrong.

1 Expert replyverified_user

Tracking Salesforce conversions using form in iframe

Top Contributor
# 2
Top Contributor

Hi Andrew J,

You mean your landing page is on one domain, and the form is in an iFrame? So, when I click on your ad I go to www.example.com/landingpage.html, and it has an iFrame with src=www.domain.com/leadform.html and you want to pass the gclid to www.domain.com from www.example.com?

I think I get you.

Ok, when the visitor first hits you site it the only opportunity you have to capture the gclid. When the visitor hits, look for the presence of the gclid value in the query string using Javascript. When you get the value, set the src of your iFrame to www.domain.com/leadform.html?gclid=adsflkjdlfkjlksjdfls.

 

You'll need a couple functions, one to read the cookie, one to set the iFrame source.

 

function getCookie(strName) {
    var aCookie = document.cookie.split("; ");
    for (var i=0; i < aCookie.length; i++) {
        aCrumb = aCookie[i].split('=');
        if (aCrumb[0] == strName) {
            return unescape(aCrumb[1]);
        }
    }
    return null ;
}

 

function setSrc() {

   gclidvalue = getCookie('gclid');

   document.frames['leadform'].src="www.domain.com/leadform.html?gclid="+gclidvalue;

}

 

Somewhere in your html:

<iframe id=leadform></iframe>

 

Your body tag:

<body onload="setSrc();">

 

If the iFrame isn't on the landing page, you'll need a different strategy.

I haven't tested the above code, no guarantees. You may need to tweak it a little bit.

 

Best of Luck,

 

Pete

 

petebardo -- Deadhead doing AdWords

Tracking Salesforce conversions using form in iframe

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Thanks so much for this Pete, that certainly looks like a workable solution. Two questions:

 

1. The iframe is on the landing page but our visitors will tend to browse before filling in a form, but if your code is placed on any page that has the iframe that should be OK, right? The cookie will still exist throughout the session and be readable.

 

2. "www.domain.com/leadform.html?gclid="+gclidvalue; If the (hidden) input field I want to fill in is not called "gclid" I just replace that part of the URL source, correct?

Re: Tracking Salesforce conversions using form in iframe

Top Contributor
# 4
Top Contributor

Hi Andrew J,

Looks like I gave you something that won't work. Instead of looking at the cookies, you need to look at the query string. It's similar.

 

 

function getQuery(cName) {
    // cName is the name of a query value to return
    var search = document.location.search.substr(1);
    var aNames = search.split("&");
    for (i=0;i<aNames.length;i++) {
        if (aNames[i].indexOf(cName+'=') == 0) {
            cValue = decodeURI(aNames[i].substr(cName.length+1));
            cValue = cValue.replace(/+/g,' ');
            return cValue;
        }
    }
    return '';
}

function setSrc() {
   gclidvalue = getQuery('gclid');
   document.frames['leadform'].src="www.domain.com/leadform.html?gclid="+gclidvalue;
}

Somewhere in your html:
<<iframe id="leadform" height="150" width="300"></iframe> 
Your body tag:
<<body onload="setSrc();"<>:

 Now, here's the rub. The gclid value only exists in the query string when the visitor first hits you site. What I would do is set a cookie with the gclid value for your domain. That way you still have it when the user fills out the form. Here are a couple cookie functions to help you get started.

// Create a cookie with the specified name and value.
function SetCookie(sName, sValue)
{
  var strCookie = sName + "=" + escape(sValue);
  // Expires the cookie in six months
  var date = new Date();
  date.setMonth(date.getMonth()+6);
  strCookie += ("; expires=" + date.toUTCString());
  strCookie += ("; path=/; domain=www.novaspace.com;");
  document.cookie = strCookie ;
}

// Retrieve the value of the cookie with the specified name.
function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0])
      return unescape(aCrumb[1]);
  }
  // a cookie with the requested name does not exist
  return null;
}

 

The name of the hidden field is not important. How the gclid gets filled in on that page is. When we set the iFrame src including the gclid value in the query string, a script on that page needs to pick up that gclid value and put it in the hidden field. I'm not familiar with Salesforce. If the form were not in an iFrame, it would still need to pick up the gclid value from the query string somehow. I figured if we passed the name as gclid, the existing scripts should pick that up. Otherwise, you'll need a script on the framed form page to read the query string and assign that value to your hidden field.

What I would do first is test the form page by adding an arbitrary gclid name/value pair in the query string. Then look at the value of the hidden field. Does it have the gclid value in it? I use Firefox Firebug to do this. If the value isn't assigned correctly, I'd look at the Javascript on the form page (if any) to see how it assigns the gclid value to the hidden field. I'm thinking naming it gclid should work, as that's what's in the URL when someone clicks on your ad.

Doing this won't change the click count on AdWords reports, but could confuse GA.

Is the iFrame in the same domain as the top page? If it is, it will be able to read the cookie and you won't need to pass it in the query string. Scripts in the iFrame usually can not call scripts from the top page. In that case, have the top page set the cookie when the user first hits the site. Then set the src of the iFrame, without the gclid in the query string. The page should load with the cookie you just set. Then have the script on the form page read the cookie and set the form field value from that.

This is about a 4 hour job for me, at $50 an hour, longer if you are inexperienced with writing and debugging Javascript. None of what I have provided should be used without thorough testing.

Best of Luck!

 

Pete

 

 

 

 

petebardo -- Deadhead doing AdWords

Tracking Salesforce conversions using form in iframe

Top Contributor
# 5
Top Contributor

Hi Andrew J,

One more thing. I don't off hand know the case of the gclid name in the query string. It's either "gclid" or "GCLID". If it doesn't work with all lower case, try it with all upper case. The page you referenced does basically the same thing as I have outlined, although it uses a different method to get the gclid value. That page indicates it is all lower case.

Looks like the iFrame is not from the same domain.

Passing the gclid value in the query string may count extra clicks in Analytics. If it's not your site, I imagine that makes little or no difference. If it is your site, GA could end up counting page visits as paid traffic. In that case, I would use a different name for passing the gclid, and adjust all the scripts accordingly.

 

Pete

petebardo -- Deadhead doing AdWords