Mobile app version of vmapp.org
Login or Join
Tiffany637

: Why are the custom campaign parameters in Google Analytics so long? Adding several Google Analytics custom campaign parameters can make URLs very long.* For example, in Google's own examples:

@Tiffany637

Posted in: #GoogleAnalytics #Url #UrlParameters

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

For example, in Google's own examples:
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 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.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Tiffany637

2 Comments

Sorted by latest first Latest Oldest Best

 

@Ravi8258870

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

10% popularity Vote Up Vote Down


 

@Tiffany637

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme