I've got a situation where a site will have one analytics key and then on a "per section" basis I'd like to insert a second key.

I've researched this a bit and it seems possible: http://www.optimiced.com/en/2007/10/25/two-or-more-google-analytics-in-o...

What I propose is two things:
1) A hook that google_analytics module calls which other modules can implement to send back a tracking ID
2) If there are multiple tracking IDs (two or more even...) then the google_analytics code be modified to use the technique from that page I linked to insert multiple trackers on one page

Thoughts?

Comments

greggles’s picture

Status: Active » Needs review
StatusFileSize
new2.01 KB

Here's a patch which does this.

I'm using it to allow users to put a key into a cck node and then whenever someone is looking at their content my hook implementation returns a value for that user's Google analytics account number.

hass’s picture

How about using module_preprocess_page function to alter the footer? Please take a look to my example at http://drupal.org/node/284599. I have already asked about some hooks and was told we don't need more hooks.

greggles’s picture

Thanks for the feedback.

Modifying a module's output using preg_replace is an interesting idea, but it's certainly not the "Drupal" way to do it. It's pretty unreliable and prone to break.

My hook is quite specific and I can understand a desire to make it more general so that it will handle more situations (like the e-commerce situation presented in that example). But I have a hard time with the idea that this should be done with preg_replace and that it's unnecessary for a module to have any hooks (as far as I can tell, google_analytics doesn't have any hooks now, right?)

hass’s picture

Status: Needs review » Needs work

See #231451: Add hook to alter data before sending it to browser about the discussion. I was told this works we don't need a hook (http://drupal.org/node/231451#comment-904457). The patch will not work in general. It is only a solution for your specific requirements. See my hook idea at http://drupal.org/node/231451#comment-900139. Next time someone else likes to do something special like hooking a custom_url and we need to patch again and again. CNW for now.

If you have a better theming idea as the regex please share your ideas... :-)

hass’s picture

Marking this as a duplicate of #231451: Add hook to alter data before sending it to browser. Let's move over.

hass’s picture

Status: Needs work » Closed (duplicate)
psynaptic’s picture

So what exactly is the solution to having multiple GA account keys? One of my clients would like to use 2 separate accounts. One for testing and another for the real tracking.

reubenavery’s picture

Subscribing. I also have a need for this, my client is requesting tracking on two different Web Property ID's -- one that is specific to the site, and another that they're using as a "rollup" tracking account that tracks usage across multiple sites.

hass’s picture

RTFM

puddyglum’s picture

Ouch. On http://drupal.org/node/248699 I found this snippet buried in the comments:

/////////////////////////////////////////////////
// Track activity in multiple GA accounts.
/////////////////////////////////////////////////
// Usage: Put the following snippet in the
//        "Code snippet (after" section
// Example:
var otherTracker = _gat._getTracker("UA-1234567-1");
otherTracker._trackPageview();
puddyglum’s picture

I got this working in D7 by using this code in the "Advanced Settings" > "Custom Javascript Code> Code Snippet After

_gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
_gaq.push(['_trackPageview']);

https://developers.google.com/analytics/devguides/collection/gajs/?csw=1...