Track campaigns with Google Analytics without query string parameters?

后端 未结 9 1226
忘掉有多难
忘掉有多难 2020-11-30 18:52

Is there a supported way in Google Analytics to track a campaign without having to use query string parameters.

In Analytics you can tag a link to your site with que

9条回答
  •  无人及你
    2020-11-30 19:18

    _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.

提交回复
热议问题