Google Analytics for Umbraco – First Beta

5 06 2009

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


Actions

Information

19 responses

5 06 2009
Kenneth Solberg

Wow! Great work!

5 06 2009
Chris Houston

Looks good, I’ll try and install it over the weekend. Is there a particular reason you’ve not used the built in package tool?

Glad to see your going to open source this, I am sure others (me included) are likely to help contribute.

5 06 2009
Morten Christensen

No special reason for not doing an umbraco package. Seemed faster just to pack up the files, and at the same time force the user/installer to think about the settings that needs to be configured.
When I get a bit further ahead I’ll probably start creating packages using the built in package tool.

6 06 2009
bob batyb-arr

I have installed the files for your analytics section/dashboard but for some reason my statistics tree has no nodes under it… any thoughts?

thanks,

6 06 2009
Morten Christensen

Did you run the sql script (see below)? If nothing is loading, could sound like you are missing some tables in you umbraco db. If you did run the scripts, let me know which version of umbraco you are using and i’ll look into it.

USE [umbracodatabasename]
GO
INSERT INTO [umbracoApp] ([appAlias], [sortOrder], [appIcon], [appName], [appInitWithTreeAlias]) VALUES (N’stats’, 9, N’.traystats’, N’Statistics’, NULL)
INSERT INTO [umbracoUser2app] ([user], [app]) VALUES (0, N’stats’)
INSERT INTO [umbracoAppTree] ([appAlias], [treeAlias], [treeSilent], [treeInitialize], [treeSortOrder], [treeTitle], [treeIconClosed], [treeIconOpen], [treeHandlerAssembly], [treeHandlerType]) VALUES (N’stats’, N’stats’, 0, 1, 0, N’Statistics’, N’folder.gif’, N’folder_o.gif’, N’Sitereactor.GoogleAnalytics’, N’loadStatTree’)

6 06 2009
bob batyb-arr

the main folder comes up… statistics… but no subnodes… i did run the sql script.. i wonder if it is not loading the sitereactor.googleanalytics??? into the tree itself..

i am using 4.0.1

7 06 2009
Morten Christensen

Thanks for the reply.
I have been able to recreate the issue, and localize a typo in the sql INSERT statement. Please rename “loadStatTree” to “LoadStatTree” in the umbracoAppTree table or use this insert statement (if the tree doesn’t load after you have changed it, try resetting the application):
INSERT INTO [umbracoAppTree] ([appAlias], [treeAlias], [treeSilent], [treeInitialize], [treeSortOrder], [treeTitle], [treeIconClosed], [treeIconOpen], [treeHandlerAssembly], [treeHandlerType]) VALUES (N’stats’, N’stats’, 0, 1, 0, N’Statistics’, N’folder.gif’, N’folder_o.gif’, N’Sitereactor.GoogleAnalytics’, N’LoadStatTree’)

or use this update statement:
UPDATE [sitereactorUmbraco].[dbo].[umbracoAppTree]
SET [treeSilent] = 0
,[treeInitialize] = 1
,[treeSortOrder] = 0
,[appAlias] = N’stats’
,[treeAlias] = N’stats’
,[treeTitle] = N’Statistics’
,[treeIconClosed] = N’folder.gif’
,[treeIconOpen] = N’folder_o.gif’
,[treeHandlerAssembly] = N’Sitereactor.GoogleAnalytics’
,[treeHandlerType] = N’LoadStatTree’
WHERE [appAlias] = ’stats’

These are the correct inserts (please delete existing entries before applying):
USE [umbracodatabasename]
GO
INSERT INTO [umbracoApp] ([appAlias], [sortOrder], [appIcon], [appName], [appInitWithTreeAlias]) VALUES (N’stats’, 9, N’.traystats’, N’Statistics’, NULL)
INSERT INTO [umbracoUser2app] ([user], [app]) VALUES (0, N’stats’)
INSERT INTO [umbracoAppTree] ([appAlias], [treeAlias], [treeSilent], [treeInitialize], [treeSortOrder], [treeTitle], [treeIconClosed], [treeIconOpen], [treeHandlerAssembly], [treeHandlerType]) VALUES (N’stats’, N’stats’, 0, 1, 0, N’Statistics’, N’folder.gif’, N’folder_o.gif’, N’Sitereactor.GoogleAnalytics’, N’LoadStatTree’)

Let me know if this fixes your problem.

7 06 2009
bob batyb-arr

well, now i see the tree… but am getting a 400 error when i click on any of the nodes…

Stack Trace:

[WebException: The remote server returned an error: (400) Bad Request.]
System.Net.HttpWebRequest.GetResponse() +1532114
Google.GData.Client.GDataRequest.Execute() +66

[GDataRequestException: Execution of request failed: https://www.google.com/analytics/feeds/data?dimensions=ga:day&end-date=2009-06-06&ids=5305208&metrics=ga:visits&start-date=2009-05-07
Google.GData.Client.GDataRequest.Execute() +151
Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter) +369
Google.GData.Client.GDataGAuthRequest.Execute() +10
Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince, String etag, Int64& contentLength) +179

sorry, if I am being a pain… but trying to help you debug if i can :)

8 06 2009
Morten Christensen

No, not a pain at all. Its good that you find these bugs.
I can see from the URL you provided that the profile id is not in the correct format even though I added a check for this, which is obviously not working correctly. If you add “ga:” as a prefix to your profile id in the web.config it should work (giving that you provided the correct profile id ;) ).
Your web.config settings should look like this:
add key=”GoogleAnalytics.Email” value=”email@gmail.com”
add key=”GoogleAnalytics.Passwd” value=”password”
add key=”GoogleAnalytics.ProfileId” value=”ga:5305208″

Please note that the profileid you entered looks more like the tracking code (like UA-6670342-1) then the profile id (like ga:13486558).

I will fix the profile number check, so you can enter the profileid without the ga: prefix.

8 06 2009
Ian Bennett

Just installed and all working great thanks. I notice that most lists are ordered by name rather than percentage, is that easy to change?

8 06 2009
Morten Christensen

Currently the lists, which are displayed within the five views are very static, so currently not very easy to change. But I plan to make the different views a bit more generic, so they’ll be easy to move around and change. Sorting has not previously been a concern, but I will take it into consideration. If I find an easy solution I will definitely add sorting capabilities ;)

8 06 2009
bob batyb-arr

sorry i did not try the ga: prefix… i had in my other testing but forgot to try that once the tree was fixed – blush — all is working great now… thanks for all your hard work, this is an awesome addition to umbraco!

23 06 2009
Fredrik Pettersson

Hi!
I downloaded the 1.02 version from the umbraco site and couldnt find any sql script. Isithe file corrupt or are there changes in how to install the package?

24 06 2009
Morten Christensen

Hi Frederik. The version available on our.umbraco.org contains package actions, but for some reason they don’t work. I’m trying to workout a fix and upload a new package.
You will however be able to find the sql-script in the zip that is available for download on this blog post -> http://www.sitereactor.dk/media/Sitereactor.GoogleAnalytics.Release_1.0.0-(Beta).zip

9 07 2009
Karl Kopp

Installed and works perfectly – nice work :)

18 08 2009
Thomas
7 12 2009
Niels Bosma

Thanks for a great package, I’m really looking forward to have a look at the sourcecode if you go through with that. I have some features specific to my site that I’d like to add.

7 12 2009
Morten Christensen

Hi Niels, the sourcecode is actually already available on codeplex: http://gaumbraco.codeplex.com/ but its still work-in-progress, so I wouldn’t recommend using or modifing it just yet.

Keep an eye on twitter ;) I expect a teaser of some sort to be sent out sometime this week :)
http://twitter.com/sitereactor

When the project reaches the next step, I’ll twit and blog to get the word out there.

- Morten

11 01 2010

Leave a comment