Forum: Ruby on Rails google_analytics gem problems

Posted by phil (Guest)
on 2008-08-13 00:19
(Received via mailing list)
I've honestly never had any serious issues with a gem under RoR until
now!

I installed mark catley's google analytics plugin (http://github.com/
markcatley/google_analytics/tree/master) and it doesn't seem to work
at al! I have the gem in my environments.rb (I am running Rails 2.1),
and it is installed. But it is like it is not loaded in. There is no
call added and if I try and hand add an after_filter to call
add_google_analytics_code I get a no such method error.

Has anyone used this gem?
Posted by MikeG1@larkfarm.com (Guest)
on 2008-08-13 03:40
(Received via mailing list)
A few things to check:

1) If you're testing in development, make sure your config/
initializers/analytics.rb file includes a line like this:

Rubaidh::GoogleAnalytics.environments = ['production', 'development']

(By default, the Analytics code is only added in the production
environment)

2) Make sure that you're testing with a page that goes through a
layout with <body><body> tags - the code depends on seeing the body
tags to know where to insert code. Don't be fooled by "view source"
showing you body tags that aren't really there if you're simply
rendering a view without a layout.

3) You may want to pick up from the master repo at
http://github.com/rubaidh/google_analytics/tree/master , which I
believe is somewhat more up-to-date than Mark Catley's branch.

I just ran a test using the current master code as a gem in a Rails
2.10 app, and it worked fine for me.
Posted by phil (Guest)
on 2008-08-13 09:59
(Received via mailing list)
Thanks Mike!

I installed the code from git://github.com/rubaidh/google_analytics.git
as a plugin and that seemed to work. Using it as a gem I had no
success... how did you do it?

Now the question is, is it any better than just having the code in a
partial and dropping it at the bottom of my layout?!
Posted by MikeG1@larkfarm.com (Guest)
on 2008-08-13 12:39
(Received via mailing list)
All I did was add the line to the config file, run rake gems:install,
and run with it. So I'm not sure why you had issues with the gem
approach.

As to whether it's better than just dropping static code in through a
partial - that depends, I think, on whether you need to use any of the
other capabilities of the plugin. If all you need to do is just hook
pages into Google Analytics, the partial approach is fine. The two
areas where I've found the plugin most useful are (1) The helpers that
let me use link_to_tracked and so on to easily get outgoing link
tracking (2) The overrides to claim a different site/path for
different pages when making the call back to Google (I'm using that
heavily on a server where one Rails app serves multiple sites).

Of course, since I wrote a bunch of that code, I'm prejudiced.

Mike
Posted by phil (Guest)
on 2008-08-13 13:02
(Received via mailing list)
Ok,
The line in the readme, though, installs the mark catley one... so I
guess what I am asking is what line exactly did you add!
Posted by MikeG1@larkfarm.com (Guest)
on 2008-08-13 14:20
(Received via mailing list)
I used Mark's branch when testing the gem integration; he's the one
who's been working on that part of the code. I mainly run with the
plugin myself, though.

Mike
Posted by Chris Birkinshaw (chrisbirkinshaw)
on 2008-08-27 18:13
I added http://gems.github.com to my gem sources, then did a 'gem list 
-r | grep analytics', which only turned out the 
markcatley-google_analytics (1.0.20080720) version.

Following the instructions here 
(http://github.com/rubaidh/google_analytics/tree/master#) and using 
'rake gems:install' tells me that the gem does not exist.

Hmmm. So I tried installing the markcatley version 'gem install 
markcatley-google_analytics', which goes ok, but when I add 'require 
'rubaidh/google_analytics' to my application controller and then 
'Rubaidh::GoogleAnalytics.tracker_id = 'xxxx'' to the bottom of 
environment.rb I get a 500 Server Error with nothing in my development 
log.

How exactly am I supposed to use this gem? I can't find any information 
anywhere which works, though if there is then please tell me where.

Alternatively how am I supposed to install it as a plugin? All the 
sources I can find on the net to pass to script/plugin install seem to 
be dead, or old code (not the latest google javascript).

Thanks,

Chris
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.