We recently moved from Google's Classic Analytics to Google's Universal Analytics, and I would like to share a few practices we used to make the transition easier.
- We have a Google markup Item we created in the content editor (simple text field) which we use to dynamically inject the UA code to the layout using a Literal that will accept the final <head> UA markup.
- Try to move all UA scripts from inline to a separate js file. This is a huge maintenance win for us as we have a central location where any UA changes can be made. The JS file basically is a "document.ready" script where all the elements and events we'd like to capture are placed. Use jquery's excellent 'binding' capabilities to be able to 'attach' an event to any specific element you have in your Sitecore pages.
- We have another version of this same JS file that basically just contains pop-up alerts containing the actual UA call. This helps our SEO Analysts to check if the scripts are formatted correctly and are properly triggered.
- For pages like static pages that are not using the central JS file, we ran a custom command line utility utilizing regex to 'parse' each line, picking out the classic GA scripts and replacing them with the UA version. Something like the one below:
Regex regex = new Regex(@"_gaq\.push\(\['_[^']*'(,? ?[^,(\]\);)]*){0,4}?]\);");
if (regex.IsMatch(line))
{
....do some stuff here
}
Comments
Post a Comment