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?
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | 324764_google_analytics_multiple_accounts.patch | 2.01 KB | greggles |
Comments
Comment #1
gregglesHere'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.
Comment #2
hass commentedHow 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.
Comment #3
gregglesThanks 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?)
Comment #4
hass commentedSee #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... :-)
Comment #5
hass commentedMarking this as a duplicate of #231451: Add hook to alter data before sending it to browser. Let's move over.
Comment #6
hass commentedComment #7
psynaptic commentedSo 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.
Comment #8
reubenavery commentedSubscribing. 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.
Comment #9
hass commentedRTFM
Comment #10
puddyglumOuch. On http://drupal.org/node/248699 I found this snippet buried in the comments:
Comment #11
puddyglumI got this working in D7 by using this code in the "Advanced Settings" > "Custom Javascript Code> Code Snippet After
https://developers.google.com/analytics/devguides/collection/gajs/?csw=1...