我有一個提取Google Analytics信息(___umtz)的JS代碼。我只想獲取搜索詞 - 但是,在Firefox上,它始終顯示爲「(未提供)」。在Chrome上,我可以獲取使用的關鍵字,但在FF上,該Cookie列出爲'(未提供)'使用Javascript從Google Cookie中提取關鍵字
舉例: utmcsr = google | utmccn =(有機)| utmcmd =有機| utmctr =(不是%20提供)
utmctr是alwayts(未提供),無論我用什麼關鍵詞爲我的網站。
下面是一個例子代碼:
function parseCookie(name)
{ 如果(!document.cookie.indexOf( 「__ utmz =」)= - 1){ VAR C2 = readCookie(名); //獲取cookie var ca2 = c2.split('|'); //這個分裂的cookie插入部分
temp = ca2[0].split('.'); // This grabs the first variable together with the numerical info
temp2 = temp[temp.length - 1]; // This takes only the variable we are interested in
ca2[0] = temp2; // We then replace the item in the array with just the variable data
var src = ' '; // Will contain the source, if there is one
var campaign = ' '; // Will contain the campaign, if there is one
var medium = ' '; // Will contain the medium, if present
var term = ' '; // Will contain keyword info, if present
var cancel = false; // Used to check for AdWords ID
for (i = 0; i < ca2.length; i++)
{
temp3 = ca2[i]; //First, take each variable (ex. utmcsr=sourcename)
temp4 = temp3.split('='); //Splits into an array, with temp4[0] = 'utmcsr, and temp4[1] = 'sourcename' using our above example
if (temp4[0] == 'utmgclid') //Identifies the varaible and replaces appropriate items for Google Adwords Campaigns
{
src = 'google';
medium = 'cpc';
campaign = 'google';
cancel = true;
}
if (temp4[0] == 'utmccn' && !cancel)
{
campaign = temp4[1];
}
if (temp4[0] == 'utmcsr' && !cancel)
{
src = temp4[1];
}
if (temp4[0] == 'utmcmd' && !cancel)
{
medium = temp4[1];
}
if (temp4[0] == 'utmctr')
{
term = temp4[1];
}
}
alert(term);
}
}