Project

General

Profile

New Google Analytics Plugin that supports per-project tracking!

Added by Cyrus Amiri over 15 years ago

Please visit:
http://labs.novaleaf.com/wiki/gap4redmine
as it is the home of a new Google Analytics Plugin I just created.

This plugin was inspired by Eric Davis' original Google Analytics plugin, but, supports customized per project tracking, and some other differences.
I'm in no ways a Redmine or ROR expert - so apologies if I did anything wierd/odd.

I LOVE REDMINE!


Replies (5)

RE: New Google Analytics Plugin that supports per-project tracking! - Added by Eric Davis over 15 years ago

The Whys

I'll start with the answers to your Whys. These are my opinions only but they influenced the design of my plugin version and might help someone decide which version to use:

  • The plugin did not allow for project-specific Google Analytics Tracking.

That could be useful but I didn't have the need to add that. If others want this feature, I'd be happy to work with you on implementing on my plugin.

  • The plugin required users to enter the full Google Analytics tracking script.

I figured this was the easiest UI because when you register with Google they tell you "Paste this onto your website". Technical people might understand what part is the unique code but I wanted to make it accessible to non-technical people also.

  • The plugin has support for options which allow you to ignore tracking if a person is not logged in, or, not an administrator. I'm not convinved these properties are entirely vital.

There's a simple reason for that, I'm an administrator and I don't want to track my views. :) I could also see a use case of someone only wanting to track anonymous users.

The Code

The code is pretty straight forward and I'm overjoyed to see someone else using the new plugin hooks.

A Bug

I am getting an error whenever I'm not in a project though.

Processing AdminController#index (for 127.0.0.1 at 2008-11-06 15:46:29) [GET]
  Session ID: f0fa440841a90f75a6ab28d51305e72b
  Parameters: {"action"=>"index", "controller"=>"admin"}
Rendering template within layouts/base
Rendering admin/index

ActionView::TemplateError (undefined method `module_enabled?' for nil:NilClass) on line #65 of layouts/base.rhtml:
62:     Powered by <%= link_to Redmine::Info.app_name, Redmine::Info.url %> &copy; 2006-2008 Jean-Philippe Lang
63: </div>
64: </div>
65: <%= call_hook :view_layouts_base_body_bottom %>
66: </body>
67: </html>

    vendor/plugins/google_analytics_plugin/lib/google_analytics_hooks.rb:18:in `view_layouts_base_body_bottom'
    lib/redmine/hook.rb:60:in `send'
    lib/redmine/hook.rb:60:in `call_hook'
    lib/redmine/hook.rb:59:in `each'
    lib/redmine/hook.rb:59:in `call_hook'
    lib/redmine/hook.rb:103:in `call_hook'

A Fix

I think you need to guard like this:

#### This block added, though it could be refactored into the existing blocks also
# no project or master key has been set - render nothing
if ((context[:project].blank?) && (master_analytics_key.blank?))
  return ''
end

# no project, key has been set - spit the analytics script into the footer
if ((context[:project].blank?) && (!master_analytics_key.blank?))
  return get_analytics_text(master_analytics_key);
end

# project enabled, module enabled
if context[:project].module_enabled?('google_analytics')        

The Conclusion

Cyrus's plugin is good and I like how it was made to be configurable per project. I want to thank him for open sourcing this so now the community has options for using Google Analytics.

Suggestions

  • Edit the Plugins page to add your plugin or ask someone to add it for you.
  • Change the name of it so it will not conflict with the existing plugin. This also includes your settings partial. See #2018
  • Put the source code repository online so others can get the code directly. GitHub is best but a svn repository would work also.

Eric

RE: New Google Analytics Plugin that supports per-project tracking! - Added by Cyrus Amiri over 15 years ago

Response to "The Bug"

Eric - First of all, thanks for being the source of this bug:
http://labs.novaleaf.com/issues/show/5

A new version of the plugin (v0.1.1) is now up on
http://labs.novaleaf.com/wiki/gap4redmine

Responses to "The Whys"

RE: per-project features

Glad to see you think this is valuable!

RE: tracking code generated automatically vs. manually

I think this is just a matter of preference. I'm used to the Wordpress/WordpressMU plugin which lets you be lazy! Personally, I always think of analytics in terms of the tracking code. That's why I did it this way.

RE: The anon/admin filtering options...

You are correct, I was wrong, regarding the anonymous/admin filtering. I bow to your logic. In fact, now, I can see more cases than this... There's probably a lot of value to be gained by doing research on google analytics plugins for other projects and finding out what features may or may not be supported for future versions. I'll probably start looking into that when I get more free time.

Responses to your "Suggestions"

Re: Adding to the Plugins page... No way! No way! No way! I think it would be a very bad thing for the Redmine community if there were two plugins for Google Analytics. It's such a basic feature. To have two of these plugins with slightly different feature sets would just be confusing and a pain. Methinks it would also look quite odd on the Plugins page! The nature of open source is to collaborate - so, in my mind, the best thing would be if we could combine forces and features. If not, hrmm, I'll probably just let remain an obscure plugin and collect dust.

- Cyrus

RE: New Google Analytics Plugin that supports per-project tracking! - Added by Eric Davis over 15 years ago

Cyrus Amiri wrote:

RE: The anon/admin filtering options...

You are correct, I was wrong, regarding the anonymous/admin filtering. I bow to your logic. In fact, now, I can see more cases than this... There's probably a lot of value to be gained by doing research on google analytics plugins for other projects and finding out what features may or may not be supported for future versions. I'll probably start looking into that when I get more free time.

That's a great idea. Please post anything you find out about other plugins here. My analytics plugin was created because I wanted to answer one question: "How popular is my site?" I decided to Open Source it because I figured other people could use it.

Responses to your "Suggestions"

Re: Adding to the Plugins page... No way! No way! No way! I think it would be a very bad thing for the Redmine community if there were two plugins for Google Analytics. It's such a basic feature. To have two of these plugins with slightly different feature sets would just be confusing and a pain. Methinks it would also look quite odd on the Plugins page! The nature of open source is to collaborate - so, in my mind, the best thing would be if we could combine forces and features. If not, hrmm, I'll probably just let remain an obscure plugin and collect dust.

Good to hear you feel that way. I'd hate to have the community support multiple similar plugins but that's always a possibility. We can talk about merging the features of the two.

Eric

RE: New Google Analytics Plugin that supports per-project tracking! - Added by Cyrus Amiri over 15 years ago

I started doing a little research on other Google Analytics plugins on the net.
It seems that, yep, there's more features to consider:

Filtration based on context

UGA for WordPress lets you individually enable/disable analytics tracking for blog entries and comments. There's no 1to1 correspondence in Redmine, but, there are similarities. For instance, do you really want to track your forums? What about your bugs? If users have no way to filter out tracking on contexts that cause noise, they may become frustrated. The most simple solution would probably be to create an "enabled" checkbox for forums, bugs, ? A more complicated (yet versatile) feature may be a list of matching patterns - although, it would turn up the complexity of the feature. More thought required, but you get the idea.

Tracking Downloads

Another feature I see is the ability to add tracking for downloads of (local on server) files. The user generally has to inform the plugin of the types of files it wants to track. Optionally, the user can specify a "virtual folder" name to allow for simpler grouping when they view analytics.

Tracking External Links

This one's kind of funny. I've not used the feature myself, but, assume the plugin is "hijacking" the link clicks with some javascript and doing something similar to what's done in the Tracking Downloads feature. Again, a similar option to specify a "virtual folder" exists. This feature sometimes requires information about what links are considered internal - users sometimes don't use relative pathing. Seems like the external link tracking would be the most interesting if you had the forums turned on :).

Tracking mailto's

Similar stuff.

Anyways, this was just a small amount of research, but, I think it shows there's more stuff to think about too.

Maybe we could have a discussion sometime about combining the plugin features and/or discussing some of the features listed above.

RE: New Google Analytics Plugin that supports per-project tracking! - Added by Eric Davis over 15 years ago

Cyrus Amiri wrote:

Filtration based on context

The most simple solution would probably be to create an "enabled" checkbox for forums, bugs, ?

That sounds like a good idea.

Tracking Downloads

Another feature I see is the ability to add tracking for downloads of (local on server) files.

I've been thinking about this myself also. Shouldn't be too difficult since Redmine doesn't just link to the file directly (it goes through the attachment controller).

Maybe we could have a discussion sometime about combining the plugin features and/or discussing some of the features listed above.

Sounds great to me, I should be having some time free up soon.

Eric

    (1-5/5)