Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Adding several Google Analytics custom campaign parameters can make URLs very long.*

For example, in Google's own examples:

http://www.example.com/?utm_campaign=spring&utm_medium=referral&utm_source=exampleblog
http://www.example.com/?utm_campaign=spring&utm_medium=email&utm_source=newsletter1
http://www.example.com/?utm_campaign=spring&utm_medium=email&utm_source=newsletter1&utm_content=toplink

Are there shorter alternatives that GA will pick up?

* In some implementations, this can be bad for user experience, and could even decrease the likelihood of being shared.

share|improve this question
    
Why does this matter? Is it actually preventing you from doing something? –  Su' Jul 4 '13 at 10:11
    
@Su', because overly long links can negatively impact UX, with decreased share-ability on social media, online comments, etc. –  Baumr Jul 4 '13 at 10:38

2 Answers 2

up vote 2 down vote accepted

You can, if you are willing to add some additional code to your website. You need to call _setAllowAnchor(true) and add the parameters to a hash query. Here's a proof of concept:

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-XX']);
_gaq.push(['_setAllowAnchor', 'true']); // tell GA to read params from hash
_gaq.push(['_trackPageview']);
_gaq.push(function(){
    history.pushState("", document.title, window.location.pathname); // remove hash
});

var campaign = "spring";
var medium = "email";
var source = "source";
var content = "content";

// add params to hash, if some condition is true
if (true) {
    window.location.href = "#utm_campaign=" + campaign + "&utm_medium=" + medium + "&utm_source=" + source + "&utm_content=" + content;
}

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

share|improve this answer
    
Awesome solution, thanks! –  Baumr Jul 4 '13 at 11:28

No, there are no alternatives as of yet, sinceutm_source and utm_medium are required.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.