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.
(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.
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?!
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.
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.
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.
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).