Track campaigns with Google Analytics without query string parameters?

_set campaignParams

Your theoretical “_setCampaignData” finally exists, in the form of ["_set","campaignParams",...]

If you have a way to programmatically inject the values you’d like to set (for example, set by a cookie on a redirect, or on the server side and printed onto the page), you can use the _set API to hard-code the campaign params that you’d like to set.

The format for that is just:

_gaq.push(['_set', 'campaignParams', 
'utm_campaign=CAMPAIGN&utm_source=SOURCE&utm_medium=MEDIUM']);

So, using your original example:

 var campaignMedium = <%= ViewData.Model.CampaignMedium %>;
 var campaignSource = <%= ViewData.Model.CampaignSource %>;
 var campaignName = <%= ViewData.Model.CampaignName %>;
 _gaq.push(['_set', 'campaignParams', 
'utm_campaign=' + campaignName +  '&utm_source=" + campaignSource +"&utm_medium=' + campaignMedium]);

Update 2017

This answer details how to accomplish this with the newer Google Analytics library, analytics.js/Universal Analytics.

Leave a Comment