Archive

Posts Tagged ‘google analytics’

Google Analytics for Umbraco – First Beta

I’m happy to announce the first beta release of my Google Analytics plugin/section for Umbraco.
The development took a bit longer then first anticipated, but I think it turned out really well. There are still a few bugs, so I don’t recommend that you install it in a customer solution just yet. This first release is a beta release, so first off you should just try it out and please feel free to report any bugs you might find.
When I have had a chance to clean up the source code, and documenting it I will release the code as open source.

Currently known bugs are:
When submitting a new date range the first click on the button doesn’t raise the click event of the button, so you have to make your selection again and click the button to refresh the view with your new date range (default date range si one month).
I’m currently using Googles Chart API to display the charts, so the amount of data that can be displayed is limited.

At the bottom of this post you will find a link to download the files necessary to install the google analytics plugin. This is not a “normal” umbraco package that you can install from within the client, so need to unpack the files within the root directory of you umbraco installation.
These files are included in the package:
web.config
umbracoAppInserts.sql
umbracoAppTreeUpdate.sql (only needed if you have downloaded the package before – contains sql fix).
bin\Google.GData.Analytics.dll
bin\Google.GData.Client.dll
bin\Sitereactor.GoogleAnalytics.dll
config\Analytics\Analytics.config
config\Analytics\AnalyticsChartProperties.config
umbraco\config\lang\*.xml
umbraco\statistics\StatContent.aspx

So, there are a couple of things that you have to be aware of when installing/unpacking these files.
First off, the web.config file is just a standard umbraco web.config so be sure not to overwrite you own. This file is simply included to shown you how and where to configure the google analytics account that you want displayed within Umbraco.
Under <appSettings> you have to add the following to your web.config file:
<add key=”GoogleAnalytics.Email” value=”email@gmail.com”/>
<add key=”GoogleAnalytics.Passwd” value=”password”/>
<add key=”GoogleAnalytics.ProfileId” value=”ga:profileid”/>

These three entries are your Google Analytics credentials. If you are unsure of what your profileid number is, then login to analytics, click on the account you want shown within umbraco, click view report and the id value of the querystring is your profileid :)

The umbracoAppInserts.sql file is a sql script that creates three entries in your umbraco database, which will make the Statistics section appear within umbraco. Before you run this script, open it up and replace [umbracodatabasename] with [your db name].

Finally, in “umbraco\config\lang\” I have included the newest language files (from the 4.0.2.1 release) as all of these files include a translation for “Statistics” (the name of the section). You only need to extract these to your umbraco\config\lang directory if the section name looks like this: [stats]

I have included the latest release build of the Google Analytics .NET API, which is needed to get access to and retrieve data from the service.

The Sitereactor.GoogleAnalytics assembly contains all my wonderfull code :) -> Connecting to and retrieving analytics data feeds, manipulating the data and forming URLs for retrieving Google Charts (check out the API here). If you have a suggestion for another Chart implementation then googles, please let me know (should be open source).
All of this code will become open source very soon.

StatContent.aspx handles the analytics views within umbraco.

Analytics.config and AnalyticsChartProperties.config are used to configure the five views within the statistics section (Dashboard, Visitors, Traffic Sources, Content and Goals). These views are exactly what you find on the Google Analytics site with the only difference that it is currently not possible to click the statistics and get a detailed view (this will be included in a future release).
The usage of <section name=”Dashboard”> and <report name=”Pageviews” chartType=”" chartData=”" aggregateType=”"> within the Analytics.config-file is currently strongly typed, so you shouldn’t mess to much with this file – if you change the name attribute something will break or not shown up :)
The AnalyticsChartProperties.config-file you can go crazy with :) Values/InnerText only, though. Here, the size and color of small and large charts are specified. For example, a large SingleLineChart has a width of 500px and height of 125px, so if you want to increase that or maybe just change the color of the line, be my guest.

I think that was pretty much it. Let me know if you have any problems installing the section or experience bugs or differences in the datasets, please let me know (after you have double checked ;) ). All feedback is appriciated.

Here are some screens of what to expect – file at the bottom.

Download the package from our.umbraco.org.

UPDATE: Package updated with sql insert and update script.
Previous package had a typo in the umbracoAppInserts.sql script (the column “treeHandlerType” in the “umbracoAppTree” table had “loadStatTree” – should be “LoadStatTree”). Caused the five nodes not loading.

PS: This release was only been tested with umbraco v4.0.1. If you have trouble installing it with v3, please let me know and I’ll look into it.

UPDATE (07/07-09): This blog post is a bit our of date with regards to the installation of the add-in for umbraco. Please look to the project page on our.umbraco.org for the latest package.
Current package is GoogleAnalytics_1.0.2-fixed.zip.
Google Analytics for Umbraco Project page