Bættu við Google Analytics herferðar fyrirspurnum Dynamic með því að nota jQuery

jquery

Vinur Todd Baker sent me a solution via twitter for a problem that I haven't had an opportunity to develop a solution for. Since our blogs on Compendium are sometimes hosted on a secondary domain for a client, we'd like to pass Google Analytics campaign code to the primary domain so they can track visitors effectively.

Another difficulty, though, is ensuring your bloggers always include a campaign code… something that should not be expected. The correct solution is to utilize JavaScript to dynamically add the campaign code when the page loads.

document.ready(function() {
var campaignQueryString = '?{fill this in}';
var targetDomain = '{fill this in}';
$("a[href='http://www." + targetDomain + "]'").each(function() {
this.href += campaignQueryString;
});
});

Þessi sérstaka lausn notar og krefst jQuery, opins JavaScript ramma. Ég er a mikill aðdáandi jQuery til að bæta fínum áhrifum á vefsíður . Ég hef heyrt viðbrögð um að sumir fyrirtækjahönnuðir þakka ekki fyrir að reyna að fylgjast með útgáfunni.

If you use the above code, you must include jQuery. I'd recommend loading it from Google. Since many people are doing this, your page will load much faster since the code is cached, having been loaded before.


Google even supplies a URL Builder to show you how to build your campaign querystring. If you want to really get fancy, I'd recommend adding in elements like keywords, categories, authors, etc.

Ein athugasemd

  1. 1

Hvað finnst þér?

Þessi síða notar Akismet til að draga úr ruslpósti. Lærðu hvernig ummæli þín eru unnin.