Sunday, May 19, 2024
23
rated 0 times [  28] [ 5]  / answers: 1 / hits: 22125  / 15 Years ago, mon, june 1, 2009, 12:00:00

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 query string parameters such as utm_campaign and utm_medium which carry information about the campaign so that they can be tracked.



Google actually has an online tool to help in the creation of such links.



For instance if StackOverflow was advertising on Experts Exchange they may have a link like this :



http://www.stackoverflow.com/?utm_source=expertexchange&utm_medium=banner&utm_campaign=a-better-expert-exchange



For many reasons I don't want these clumsy looking parameters appearing in my URLS :




  • I want to encourage twittering, and long links discourage this

  • I dont want people bookmarking them with campaign IDs in

  • I want people to see a clean URL

  • I dont want search engines indexing these links.

  • I want full control about what parameters are sent to google analytics - and not leave it up to my partners to mess up the URLs they access my site with



I looked a while ago to try to find a way wherein you could set these parameters. Google has a page which at first glance looks like the solution, but actually isn't. That page describes how you can change the names of the query string parameters to something else - for instance to use src instead of utm_source you would run :



 pageTracker._setCampSourceKey(src);     


I really cannot seem to figure out why they don't make it easy to actually explicitly set the value of the utm_source key - and not just set up an alternative parameter name for it.



I remember a while back finding someone who had a kind of nasty hack, but I cant even seem to find that now. I seem to recall though that whoever it was took a copy of the analytics code and essentially branched it off and hacked at it. This is not a good solution for me!



is there an officially supported way of doing this at all, without some kind of nasty redirects.



In a nutshell I want to do something like this (ASP.NET MVC site). Give a partnet a link to my site with a URL like this :



 http://www.example.com/?cid=2dae88a8-66b1-475d-8a35-2978bd1a158c


In the controller for my MVC page I would find out what campaign this GUID related to, and set the model state. Note: this gives me the advantage that i can change the campaign parameters without having to reissue the URL.



In the page itself I would then do this:



var campaignMedium = <%= ViewData.Model.CampaignMedium %>;
var campaignSource = <%= ViewData.Model.CampaignSource %>;
var campaignName = <%= ViewData.Model.CampaignName %>;

pageTracker._setCampaignData({
utm_source: campaignSource,
utm_medium: campaignMedium,
utm_campaignName: campaignName
});
pageTracker._trackPageview();


IMPORTANT: This _setCampaignData method DOES NOT ACTUALLY EXIST. This is just 'pseudo code' for what I'd ideally like to be able to do.



Has anyone successfully managed to do anything like this?


More From » google-analytics

 Answers
12

The solution using push(['_set', 'campaignParams',... seems only to work for the legacy library ga.js.



Using analytics.js you need to specify the campaign param separately. E.g.



ga('set', 'campaignName', 'TheCampaignName...');
ga('set', 'campaignSource', 'someCampaignSource');
ga('set', 'campaignMedium', 'email');


https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#campaignName


[#99415] Thursday, May 28, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
danar

Total Points: 271
Total Questions: 94
Total Answers: 93

Location: Ecuador
Member since Thu, Jun 4, 2020
4 Years ago
danar questions
;