<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
/*
* Function: Hash Custom Variable
* Pass everything after # in document.referrer to GA custom variable
*/
(function() {
// Parse out the hash part of the referrer
var referrerHash = document.referrer.split("#")[1];
// If the hash exists, pass it back to GA
if(typeof referrerHash !== "undefined") {
_gaq.push(['_setCustomVar', 1, 'Sort', referrerHash, 3]);
}
})(); // IIFE to not leak global vars
// Have to _trackPageview after custom variable is pushed
_gaq.push(['_trackPageview']);
(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);
})();
</script>
有用的资料: