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

For example, in Google's own examples:


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.

  • 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

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
    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);

| improve this answer | |
  • Brendon, great script. Have you managed to test it anywhere? – Baumr May 22 at 19:28

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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