Skip to content

Instantly share code, notes, and snippets.

@tobiassjosten
Created August 15, 2011 18:16
Show Gist options
  • Save tobiassjosten/1147343 to your computer and use it in GitHub Desktop.
Save tobiassjosten/1147343 to your computer and use it in GitHub Desktop.
(function(_gaq) {
var path = location.pathname,
languages = ['en', 'sv'];
// We want prefix == 'en|sv|etc' or null.
var prefix = path.match(/^\/([a-z]{2})(\/.+)?$/),
prefix = prefix ? prefix[1] : null;
if (prefix && languages.indexOf(prefix) >= 0) {
// If we are on '/en|sv|etc', fallback to '/'.
var path_strip = '/' + prefix;
path = path == path_strip ? '/' : path.replace(path_strip, '');
_gaq.push(['_setCustomVar', 1, 'Language', prefix, 3]);
}
_gaq.push(['_trackPageview', path]);
})(_gaq);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment