Emanuele Del GrandeSimon_Weaver提出了一个问题:Track campaigns with Google Analytics without query string parameters?,或许与您遇到的问题类似。
回答者Yahel给出了该问题的处理方式:
_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.
希望本文对你有帮助,欢迎支持JavaScript中文网
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/24887