We've dropped this code on a few test pages to see whether or not they would help us capture data from our AdWords campaigns, and it doesn't appear that we're having much luck. Anyone mind taking a quick look to see if there are any quick fixes that would make the cookie script work? Note that I've changed our site's name with "mysite.com." Thanks in advice for any help or advice anyone can offer.
<script src="/js/public/jquery-latest.min.js" type="text/javascript"></script>
<script src="/js/public/jquery.cookie.js" type="text/javascript"></script>
<script src="/js/public/jQueryString-2.0.2-Min.js" type="text/javascript"></script>
<script type="text/javascript">
var $jQ = jQuery.noConflict();
$jQ(document).ready(function(){
var excludedReferrers = [ "mysite.com", "info.mysite.com" ];
var cookieDomain = "mysite.com";
var payPerClickParameter = "utm_keyword";
var payPerClickParameter = "utm_source";
var payPerClickParameter = "utm_medium";
var payPerClickParameter = "utm_content";
var payPerClickParameter = "utm_campaign";
var searchStringField = "#Search_String__c";
var searchEngineField = "#Search_Engine__c";
var payPerClickKeywordField = "#UTM_Keyword__c";
var payPerClickSourceField = "#UTM_Source__c";
var payPerClickMediumField = "#UTM_Medium__c";
var payPerClickContentField = "#UTM_Content__c";
var payPerClickCampaginField = "#UTM_Campaign__c";
var refer = document.referrer;
var searchString;
var searchEngine;
if ( (refer == undefined) || (refer == "") ) { ; }
else {
var referrerDomain =
refer.substr(refer.indexOf("\/\/") + 2,
refer.indexOf("\/",8) - refer.indexOf("\/\/") - 2).toLowerCase();
var excludedDomainFound = false;
var i = 0;
while ( (i < excludedReferrers.length) && !excludedDomainFound) {
var thisExcludedDomain = excludedReferrers[i].toLowerCase();
excludedDomainFound = (referrerDomain.indexOf(thisExcludedDomain) != -1);
i++;
}
if( !excludedDomainFound ) {
var searchEngines = [
{ name: "Yahoo", url: /\.yahoo\.co/i, query: "p" },
{ name: "Google", url: /\.google\./i, query: "q" },
{ name: "Microsoft Live", url: /\.live\.com/i, query: "q" },
{ name: "MSN Search", url: /search\.msn\./i, query: "q" },
{ name: "AOL", url: /\.aol\./i, query: "query" },
{ name: "Bing", url: /\.bing\.com/i, query: "q" },
{ name: "Ask", url: /\.ask\.com/i, query: "q" }
];
i = 0;
while (i < searchEngines.length) {
if (refer.match(searchEngines[i].url)) {
searchEngine = searchEngines[i].name;
searchString = $jQ.getQueryString({ ID: searchEngines[i].query,
URL: refer, DefaultValue: "" });
break;
}
i++;
}
if (i == searchEngines.length) {
searchEngine = referrerDomain;
var queries = ["q","p","query"];
var i = 0;
while ((i < queries.length) && (searchString == undefined)) {
searchString = $jQ.getQueryString({ ID: queries[i], URL: refer });
i++;
}
if (searchString == undefined) {
searchString = "None";
}
}
var payPerClickWord = $jQ.getQueryString({ID: payPerClickParameter,
URL: refer, DefaultValue: "" });
$jQ.cookie('mktoPPCKeyword', payPerClickWord,
{expires: 730, path: '\/', domain: cookieDomain});
$jQ.cookie('mktoSearchEngine', searchEngine,
{expires: 730, path: '\/', domain: cookieDomain});
$jQ.cookie('mktoSearchString', searchString,
{expires: 730, path: '\/', domain: cookieDomain});
}
}
$jQ(searchStringField).attr("value",$jQ.cookie('mktoSearchString'));
$jQ(searchEngineField).attr("value",$jQ.cookie('mktoSearchEngine'));
$jQ(payPerClickKeywordField).attr("value",$jQ.cookie('mktoPPCKeyword'));
});
</script>