Skip to content
This repository was archived by the owner on Aug 22, 2024. It is now read-only.

Developer Resources

MisterPhilip edited this page Dec 26, 2012 · 3 revisions

This documentation is primarily aimed for use by other developers to include Google Analytics tracking within their applications. Regular users can safely ignore this wiki page.

Background

The Tag Planet Google Analytics application allows users enhance the default tracking provided on various products by IPS.

Using (TP) Google Analytics in your applications

If you're already familiar with the JavaScript implementation of Google Analytics, integrating this application with yours will be very easy for you. If not, don't worry - it isn't terribly complicated!

Basics

In the JavaScript implementation of Google Analytics, you have an array variable that you push data into. Below is an example:

_gaq.push(['_trackEvent', 'Event Category', 'Event Action', 'Event Label']);

With this application, you'd do the following to do the same implementation:

$this->registry->googleAnalytics->_trackEvent('Event Category', 'Event Action', 'Event Label');

Basically, you're passing in the same parameters, in the same order to the same functions.

When creating a hook or integrating, check to make sure that the user has the application installed (both within the hook with the following code, and with a 'Requirement' setting):

if ( ipsRegistry::isClassLoaded( 'googleAnalytics' ) )
{
   // do your analytics hook here
}

Events

Events are the most common feature to integrate into your application. Some examples of events would be:

  • User Registration
  • New post / reply

You'd pass events as shown in the previous example:

$this->registry->googleAnalytics->_trackEvent('Event Category', 'Event Action', 'Event Label');

While there is no right or wrong naming schema, the following is recommended for usage:

$this->registry->googleAnalytics->_trackEvent([Application Name], [Object in question], [Action done]);
  • [Application Name] is the name of your application. IPS default ones are core, members (used for registration, profile view, etc.), and forums (used for topic view / post).
  • [Object in question] is what the user is viewing / doing an action to. Some examples would be a "topic", "user", or "blog entry".
  • [Action done] is what the user did to the item in question. Some examples would "new topic", "new reply", "edit post", "registered account", "activated account". The list goes on and on.

While this might look all foreign, here are some examples that might clear it up:

// New user registration:
$this->registry->googleAnalytics->_trackEvent('members', 'user', 'register');

// Profile view (e.g. http://community.invisionpower.com/user/169839-misterphilip/)
$this->registry->googleAnalytics->_trackEvent('members', 'user', 'profile view');

// New topic (successfully posted)
$this->registry->googleAnalytics->_trackEvent('forums', 'topic', 'new topic');

// New reply to a topic (Successfully posted)
$this->registry->googleAnalytics->_trackEvent('forums', 'topic', 'new reply');

// New blog post
$this->registry->googleAnalytics->_trackEvent('blogs', 'post', 'new post');

// New blog post
$this->registry->googleAnalytics->_trackEvent('blogs', 'post', 'edit post');

// New blog post comment
$this->registry->googleAnalytics->_trackEvent('blogs', 'post', 'new comment');

As you can see, there are virtually limitless things you can track. Ultimately you should leave some of the options up to the users by including the hooks to track certain events. Even if these hooks are turned off, your application should still work without any issues.

Custom Variables

Custom variables are a bit trickier since there are only 5 allowed for a whole site. By default, the user has a choice within the interface on what they should use for these slots, if anything. You can add to this list by [@TODO]

Clone this wiki locally