Closed (fixed)
Project:
Google Analytics
Version:
5.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
4 Oct 2007 at 22:56 UTC
Updated:
1 Dec 2010 at 09:53 UTC
Jump to comment: Most recent file
Comments
Comment #1
todd nienkerk commentedI edited my local copy of the module to do this.
First change: Add new textarea to hook_admin_settings()
This was added immediately above this line:
$form['advanced']['googleanalytics_codesnippet'] = array(Second change: Pull the variable in hook_footer()
This was added immediately below this line:
$codesnippet = variable_get('googleanalytics_codesnippet', '');Third (and final) change: Output the variables in hook_footer
This replaced the following line:
$script .= '<script type="text/javascript">'. $downloadtracker ."\n_uacct = \"". $id ."\";urchinTracker();{$segmentation}{$codesnippet}\n</script>\n";Comment #2
hass commentedplease provide a patch. thx
Comment #3
todd nienkerk commentedI've created a patch to add my changes to the dev version of the module. :)
Comment #4
hass commentedDo you have examples what we can add as custom variables here?
Comment #5
todd nienkerk commentedHere's a variable that allows Google Analytics to track several subdomains within one profile:
_udn="mydomain.com";Here's a more detailed explanation of
_udn, and here's a list of some other variables you can use.Comment #6
hass commentedThank you for this links, saved some time.
I would say your patch doesn't fit the real need here. Well it will work for your domain variable, but as you can see on your linked page there are many params that need to be set dynamically per page. You patch works only on global level and will therefor not work for other needs. The idea about adding this additional params is very good and we should think about a better API or hook way. A hook will allow other modules to set their variables. For e.g. Adwords may add their setting and e-commerce module can set their own things...
Comment #7
todd nienkerk commentedCan a new version of Google Analytics at least support global variables prior to the urchinTracker() call? I realize it won't suit absolutely every need, but it's a step in the right direction.
Comment #8
hass commentedAs i remember from core comments - we should avoid using global variables wherever possible. Today I'm thinking more of a
hook_google_analyticswith an array of settings... i will try to build an first version and then we see if this would be good practice.Maybe budda could comment on this if he know about a better way, i haven't thought about yet...
Comment #9
todd nienkerk commentedI think we may be misunderstanding each other with regards to "global variables." I'm not advocating creating a Drupal-wide variable -- I'm simply saying it would be useful to have a way to set additional Google Analytics variables prior to the urchinTracker() call. This is absolutely necessary for sites with several subdomains whose traffic should be monitored at the primary domain level.
While creating a hook for other modules is probably useful (I haven't thought about it myself), the ability to add one or two site-wide Google Analytics variables seems like a useful way to enhance the module -- especially for users who don't know how to work with modules or hooks.
The client I'm working with, for example, had no interest in using the Google Analytics module until I made the changes that allowed him to add a variable to the output. Now he has an easy way to add them: just a simple text area.
Comment #10
akrywko commentedI have the same request.
This is also necessary for monitoring additional search engines.
For example:
_uOsr[_uOsr.length]="onet.pl"; _uOkw[_uOkw.length]="qt";
_uOsr[_uOsr.length]="wp.pl"; _uOkw[_uOkw.length]="szukaj";
Comment #11
rconstantine commentedAnother alternative would be to store all of the code, from this line:
$script .= '<script type="text/javascript">'. $downloadtracker ."\n_uacct = \"". $id ."\";urchinTracker();{$segmentation}{$codesnippet}\n</script>\n";(distilled of course) to the variables table. This would allow it to be fully customized. It could come with what it has now as a default. Either the README could tell us what to put, or the install function could insert the variable into the table.Another reason this would be good is that if a setting was also made to select between urchin.js and ga.js, then the code could all be changed easily to match. I have changed my copy to work with ga.js. Still testing. I did not implement the changes I'm suggesting.
For those interested, change the above-mentioned line to:
$script .= '<script type="text/javascript">'. $downloadtracker ."\nvar pageTracker = _gat._getTracker(\"". $id ."\");pageTracker._setDomainName(\"yourdomain.com\");pageTracker._initData();pageTracker._trackPageview();{$segmentation}{$codesnippet}\n</script>\n";where yourdomain is your domain. I think you leave off the subdomain. See http://www.epikone.com/blog/2007/11/19/tracking-sub-domains-with-google-... for an article on tracking all subdomains with one profile in a more flexible way than the old way.
Comment #12
rconstantine commentedOh, I forgot to say that you would also need to change references to urchin.js to point to ga.js.
Comment #13
hass commentedUse $codesnippet for adding static variables to GA, please. The order have been changed in latest D5 and D6 code. Dynamic variables could be added in the way budda described here http://drupal.org/node/142514#comment-552592.
Comment #14
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.