Google Analytics integration

A Google Analytics integration for SDL Tridion has already been available for a long time, but this only consisted of a Template Building Block which added the necessary Javascript to your page at Publishing time. This integration adds to that the posibility to directly see Google Analytics data through a UI eXtension. On every Publication (provided that the Google Analytics Site ID is specified) you can see the analytics data for the asscociated website directly in the CMS interface. On top of this you can even zoom in on the specific Page analytics, just by selecting a Page in the SDL Tridion 2011 UI and pressing its Page Analytics button in the ribbon.

ribbon buttons  

analytics dashboard

publication metadataTo provide the link between a SDL Tridion Publication and a Google Analytics (web)site you need to specify the Google Analytics IDs on the Publication Metadata (example Publication Metadata Schema is provided). This consits of the Google Analytics Tracking ID (used by the Template Building Block to generate the Google Analytics Javascript code on every Published Page, so this no longer requires separate parameters on the Page Template), and the Google Analytics Site ID. These IDs can be obtained directly from the Google Analytics website after logging in and registereing your site profile.

On the Overview of your site in Google Analytics you see the account number (also known as a Tracking ID or Urchin ID) you need to use for this site (UA-xxxxxx-xx). If you register subdomains, they will automatically get a different Tracking ID, which you can specify in the Metadata of the (child) Publication. When you press the Edit button on the specific site, you can see its profile. On the profile page you will find teh Google Analytics Profile ID, which you need to use as the Site ID. This will be used to directly you to the correct profile in case you have multiple websites registered in Google Analytics.

analytics overview 

analytics profile

Installation

This eXtension comes with full source as a Microsoft Visual Studio solution which you can directly compile and deploy (you can use the free Microsoft Visual Studio Express edition). The package also contains a pre build extension which you can install using the following instructions (build for SDL Tridion 2011 Hotfix Rollup 1):

  1. Copy the files from the GoogleAnalytics (Editor).zip to a directory on your SDL Tridion CMS server, this will be your extension location (prefered location will be directly under the ..\WebUI\Editors directory).

  2. Set up the extension location as a virtual directory in IIS. 
     a)  In the IIS console, browse to the SDL Tridion 2011 website
     b)  Under the ..\WebUI\Editors directory add a new Virtual Directory, pointing to your extension location on disk (you have to do this also if the location you chose in step 1 is directly under the ..\WebUI\Editors directly as shown in the screenshot below) 

    editor vdir 

  3. Add the Tridion.GoogleAnalytics.Editor.dll to the ..\WebUI\bin directory and the Tridion.GoogleAnalytics.Editor.Strings.resx to the ..\WebUI\App_GlobalResources directory.

  4. Configure extension in the GUI. To do this, find the System.config file under <Tridion_home>\web\WebUI\WebRoot\Configuration
     a)  Make a backup of the file first so you can always revert to the way it was with no extensions configured
     b)  Locate the <editors> element and add a new editor like so:

    <editor name="GoogleAnalytics">
        <installpath>C:\Program Files (x86)\Tridion\web\WebUI\Editors\GoogleAnalytics</installpath>
        <configuration>Configuration\GoogleAnalytics.config</configuration>
         <vdir>GoogleAnalytics</vdir>
    </editor> 

     The editor element has 3 important elements:
     I)  installpath The exact location of where you copied the extension
     II)  configuration the relative location of the extension configuration file
     III)  vdir The name of the virtual directory as its set up in IIS

  5. Next step is to add the Publication Metadata to every Publication you want the analytics data for. An example Metadate Schema is provided in the zip file (Google Analytics Publication Metadata.xsd). If you already have a Publication Metadata Schema you can just add two fields to it (XML names: uaid and siteid, for details see the example Schema).
    After adding this you can fill in the needed data as directed above. 

  6. Then to get a new Google Analytics tracking code Template Building Block, you need to use the Tridion.GoogleAnalytics.Templating.dll, you can either upload this yourself in a Assembly Template Building Block, use the TcmUploadAssembly tool (as described in our documentation) or just rebuild the Template project from Visual Studio, it has a post build step to upload and create the Template Building Blocks for you (be sure to set the correct Folder ID in the post build step).   

Thats it, after a refresh of your browser you will find a Analytics group in your ribbon toolbar (in the main ribbon and on the ribbon of a Page). And you will have a Google Analytics Tracking Code TBB to add to your Page Templates. You can add this as the last block in the chain, it will add the required Javascript code directly under the </head> (so at minium it needs to be placed after your DWT TBB in the template chain).

As described this extension comes with full source code and can therefore also be used as an example of how to integrate analytics data of other vendors in a similair way.  


Developer
:    Bart Koopman
Company
License agreement
Download package
Tags
:    Google Analytics,  2011,  integration,  extension
Version
:   1.0
Source
:   Yes

About the Author
Bart Koopman
Community Development Consultant

As a Community Development Consultant, Bart is the evangelist of all SDL Tridion products. Bart used to be a consultant and trainer at SDL Tridion, supporting both partners and customers with their implementations.

SDL CMT division