views:

1133

answers:

6

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?

+3  A: 

Well, I didn’t test it, but try to add those params to the .trackPageview() method, i.e.:

pageTracker._trackPageview("?utm_source=...")

Anyways, You have to pass those parameters some how. And this means, you’ll allways have long URL-s with some kind of campaign crap in them. It won’t prevent bookmarking the wrong URL-s, search engines indexing them, etc.

If you want to maintain control of those parameters, setup separate URL-s for partners, that redirects to the tagged target URL:

http://example.com/campaigns/1 -> http://example.com/?utm_source=...
Maciej Łebkowski
Beware, remove the forward slash from the argument because it modifies the real path of the actual query.
Török Gábor
Thanks, Török, I didn’t know that this path could be relative in fact.
Maciej Łebkowski
Simon_Weaver
+1  A: 

You can use the Google Analytics API to customize the call to _trackPageview in your example.

pageTracker._trackPageview("/inbound/" + campaignSource + "/" + campaignMedium );

All of the inbound links will then show up in Google Analytics under the /inbound/ "pseudo directory" with a separate "directory" for Campaign Source and Campaign Medium.

Jay Stevens
+4  A: 

There is a function _setAllowAnchor in the Trackin API that allows you to specify the tags in the anchor text instead of as query parameters.

pageTracker._setAllowAnchor(true);

So you can use http://www.stackoverflow.com/#utm_source=expertexchange and GA will understand it. This way you can avoid the SEO problem.

For the Twitter problem, I suggest you the method described in post Tracking Twitter and Shorten URLs in Google Analytics.

Török Gábor
+7  A: 

Török Gábor gave me an idea.

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

// save the old hash
var oldHash = document.location.hash;

// add campaign data to the hash
document.location.hash = 'utm_source=' + escape(campaignSource) + ...;
pageTracker._setAllowAnchor(true);
pageTracker._trackPageview();
// restore the old hash:
document.location.hash = oldHash;

This way, you could create the campaign data in the backend, and then, pass it to the hash dynamically, and then restore it without user even noticing it. I.e. the campaign tracking is 100% independent of the real URL.

Maciej Łebkowski
This seems to mess up the browser history, at least in FF 3.5. Pressing back goes to the hashed version, back again, un-hashed version, back a third time goes to the previous page. Any tricks to keep the hash out of the history?
Nick
I'd also be worried about the page flickering while that fires off a post-back.
Jeremy Ricketts
+4  A: 

I posted this to the Google help forum.

Google Please Read!!! Great enhancement opportunity!!! This is causing a lot of users not to be able to use the Advertising parameters. Allow the Advertising parameters to be read from the URL used on trackPageview(url).

In any case, without this capability, I had to use a work-around. Rather than appending the parameters to the URL. I temporarily appended them to the URL as a bookmark. Then I removed them after the trackPageview call. By adding them as a bookmark, the page is no reloaded. See the following example.

                var pageTracker = _gat._getTracker(param);
                var orighash = document.location.hash;
                if (orighash == "") {
                    orighash = "none";  // this is done to prevent page scrolling
                }
                document.location.hash = 'utm_source='+source+'&utm_campaign='+campaign+'&utm_medium='+medium+'&utm_content='+content;
                pageTracker._setAllowAnchor(true);
                pageTracker._trackPageview();
                document.location.hash = orighash
seriously google PLEASE read !!
Simon_Weaver
This is a common workaround I've seen. (You may want to edit your post and fix the code fromatting)
Shawn Steward