Hello all,
I have found out what was causing the issue and come up with a solution. The cookies were not 3rd party, however I found that PHP is not able to read a cookie immediately after it is set. You have to browse to another page on the site or refresh the page before they become available. To get around this I used some javascript to grab the __utmz cookie and check it for the key word.
I use a script written by Michael Harrison called Google Analytics Keyword Sleuth which checks the referrer for a variety of values in the query string of the referring site (in the case of myself: Google / Yahoo / MSN). I did a few small tweaks to this script as well as adding a separate check in a javascript function that is called via the _onload_ attribute on the tag. Here is the code for anyone that is having a similar problem to mine.
The Google Analytics Keyword Sleuth: (ga_keyword.js)
| Code: : |
var keyword = null;
function noPercent(x)
{
x = unescape(x);
return x.replace(/\+/g," ").replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
function getRef()
{
ref = document.referrer;
re = /(\?|&)(q|p|query|encquery|qt|terms|rdata|qs|wd|text|szukaj|k|searchExpr|search_for|string|search_query|searchfor)=([^&]+)/;
searchq = re.exec(ref);
if(searchq) {
searchq[3] = noPercent(searchq[3]);
keyword = searchq[3];
sleuthTracker._setVar(searchq[3]);
}
else {
sleuthTracker._setVar('Referral: ' + document.referrer);
keyword = document.referrer;
}
}
function sleuth()
{
if(document.location.search.indexOf("gclid")!=-1||document.location.search.indexOf("cpc")!=-1) {
getRef();
}
}
var sleuthTracker = _gat._getTracker("UA-1");
sleuthTracker._initData();
sleuth();
|
Please note I removed the comments as they seemed to break the post
Here is my check that is called via the _onload_ attribute of the tag
[code:2]
function checkKey() {
if (keyword != null ) { document.getElementById("keyword").value = keyword; }
var utm = getCookie('__utmz');
if (utm.length>0) {
ctr_start = utm.indexOf("utmctr=");
if (ctr_start != -1) {
ctr_start = ctr_start + 7;
ctr_end = utm.indexOf("|",ctr_start);
if (ctr_end == -1) ctr_end = utm.length;
document.getElementById("keyword").value = utm.substring(ctr_start,ctr_end);
}
}
}
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}
[/code:2]
And a bit of PhP to read the cookie if it is present to hopefully have something captured even if javascript is disabled.
[code:3]
$info = explode("|",$_COOKIE['__utmz']);
$ga_info = array();
foreach ($info as $val) {
$temp = explode("=",$val);
$ga_info[$temp[0]] = $temp[1];
}
$keys = (!isset($ga_info['utmctr'])) ? (isset($_GET['OVRAW'])) ? $_GET['OVRAW'] : "Uknown" : $ga_info['utmctr'];
[/code:3]
*The $_GET['OVRAW'] value is how Yahoo passes the searched keyword
And the HTML form field (my custom field is called "Keyword")
[code:4]
[/code:4]
Hope that helps anyone that ran into the same problem as myself.