# Google analytics as extension

**URL:** <https://www.ruby-forum.com/t/google-analytics-as-extension/149871>\
**Category:** Radiant CMS\
**Created:** [September 30, 2008, 6:13pm UTC](https://www.ruby-forum.com/t/google-analytics-as-extension/149871 "2008-09-30T18:13:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjkooij](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecd19e/32.png) [@jjkooij](https://www.ruby-forum.com/u/jjkooij)\
**Post date:** [September 30, 2008, 6:13pm UTC](https://www.ruby-forum.com/t/google-analytics-as-extension/149871/1 "2008-09-30T18:13:22Z")

</div>

Google analytics, next to page tracking etc, has the option for tracking  
outbound links. It’s a very handy feature to use rather than another  
tracking software. A simple implementation of it is simple by changing  
a:

[http://davidseah.com/blog/the-printable-ceo-series/](http://davidseah.com/blog/the-printable-ceo-series/)

into

[http://davidseah.com/blog/the-printable-ceo-series/](http://davidseah.com/blog/the-printable-ceo-series/)

Is anyone working on an implementation of Google Analytics? If not I  
would like to claim it to build my first extension.

Jasper

---

<div class="post-metadata">

**Author:** ![jjkooij](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecd19e/32.png) [@jjkooij](https://www.ruby-forum.com/u/jjkooij)\
**Post date:** [September 30, 2008, 8:22pm UTC](https://www.ruby-forum.com/t/google-analytics-as-extension/149871/2 "2008-09-30T20:22:32Z")

</div>

Jasper,

What do you think about using javascript for that? That would be my  
choice.

It’s pretty easy with this jquery plugin :  
[http://jamazon.co.uk/web/2008/03/26/jquery-google-analytics-tracking-api-integration-gajs/](http://jamazon.co.uk/web/2008/03/26/jquery-google-analytics-tracking-api-integration-gajs/)

Marcus

---

<div class="post-metadata">

**Author:** ![jjkooij](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecd19e/32.png) [@jjkooij](https://www.ruby-forum.com/u/jjkooij)\
**Post date:** [October 1, 2008, 6:59am UTC](https://www.ruby-forum.com/t/google-analytics-as-extension/149871/3 "2008-10-01T06:59:24Z")

</div>

Hi Marcus,

How is the above ga tracking different from the new ga.js? That’s the  
one I’m using on my wordpress where I can specify by means of a pluging  
van joost de valk.

Here is the screenshot of the settings in wordpress for example using  
the ga.js to tag:

[http://screencast.com/t/l3orhxHo3wq](http://screencast.com/t/l3orhxHo3wq)

I’m not trying to reinvent the wheel, just measuring on a website what’s  
working and what’s not.

the outbound tag in  
pageTracker.\_trackPageview(‘outbound/[The Printable CEO™ Series – DSri Seah](http://davidseah.com/blog/the-printable-ceo-series/)’)  
and simply be replaced by a preset or specified one. I’ve checked the  
analytics and the tagging works well that way.

The only thing is that the JS code needs to be loaded before the  
pageTracker is being called.

So I’m going through the tutorial in creating an extension at the summer  
reboot [http://wiki.radiantcms.org/Creating\_an\_extension\_I](http://wiki.radiantcms.org/Creating_an_extension_I)

Jasper

---

<div class="post-metadata">

**Author:** ![jjkooij](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecd19e/32.png) [@jjkooij](https://www.ruby-forum.com/u/jjkooij)\
**Post date:** [October 1, 2008, 9:13am UTC](https://www.ruby-forum.com/t/google-analytics-as-extension/149871/4 "2008-10-01T09:13:46Z")

</div>

Hi Jasper,  
just in case you or anyone else on the list is on a fruitless search to  
also implement event tracking as part of your work with ga.js, it would  
_appear_ that this is still in beta. The event stuff is well documented,  
but I had to dig around to find out why I wasn’t seeing anything  
appearing in the GA reports. You need to apply to get on the Trusted  
Tester program to get this switched on for your account  
[http://code.google.com/apis/analytics/docs/trustedTester.html](http://code.google.com/apis/analytics/docs/trustedTester.html)

Event docs are here (basically same as pages but with additional  
parameters, which you might find useful)

> **[इवेंट ट्रैकिंग - वेब ट्रैकिंग (ga.js)
  
  |  Analytics for Web...](https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide?csw=1&hl=hi)**

regards

Ben

Adam van den Hoven wrote:

> for (var i = links.length - 1, lnk; i \>= 0; i–){  
> the anchors this way is the fastest possible way to do it.
> 
> > Jasper  
> > Post: removed\_email\_address@domain.invalid  
> > Search: [http://radiantcms.org/mailing-list/search/](http://radiantcms.org/mailing-list/search/)  
> > Site: [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)

–

Ben Still | Red Ant | office +612 9267 8300 ext 208 | mobile 0425  
294 271

---

<div class="post-metadata">

**Author:** ![jjkooij](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecd19e/32.png) [@jjkooij](https://www.ruby-forum.com/u/jjkooij)\
**Post date:** [October 1, 2008, 8:12am UTC](https://www.ruby-forum.com/t/google-analytics-as-extension/149871/5 "2008-10-01T08:12:16Z")

</div>

Jasper,

I believe that Marcus’ point was that instead of hard coding it into  
the HTML, that you write some JavaScript code to do it for you.  
Something like this should be more than fast enough for your needs:

(function (){  
//Always isolate your JavaScript from the global scope  
var links = document.getElementsByTagName(“a”),  
this\_host = window.location.host;  
for (var i = links.length - 1, lnk; i \>= 0; i–){  
lnk = links[i];  
if (lnk.host !== this\_host) {  
lnk.onClick = “pageTracker.\_trackPageview('outbound/” +  
lnk.href + “’);”  
};  
};  
})();

I haven’t tested it but it should work, more or less correctly. You  
could use a library to set the event, if you like, but looping through  
the anchors this way is the fastest possible way to do it.

Adam
