If no segmentation fields are selected on the settings page but the settings have been saved then the static variable googleanalytics_segmentation is set to be an empty array, not the empty string.
In googleanalytics.module, variable $segmentation is assigned a value iff the static variable is an array (line 63):
if(is_array($profile_fields = variable_get('googleanalytics_segmentation', '')) && ($user->uid > 0)) {
// Code to assign appropraite value to $segmentation follows ...
So if the static variable doesn't exist then $segmentation is not assigned a value; however, if the google analytics settings have been set up then $segmentation takes value __utmSetVar('');.
Why does this matter? I want to implement custom segmentation, but am concerned about having multiple calls to __utmSetVar(), with different arguments, on a single page.
Workaround: manually delete the static variable googleanalytics_segmentation from the database whenever the settings page for the google analytics module is submitted.
(Also I noticed that __utmSetVar() should be called after urchinTracker() (see http://adwords.google.com/support/bin/answer.py?answer=27219&topic=8138) - although it does seem to work as currently implemented in this module, i.e. immediately before.)
Comments
Comment #1
gpk commentedRe. placement of the call to
__utmSetVar(), it might also be better if the custom code snippet was added afterurchinTracker()(assuming that its function is to enable__utmSetVar()to be called via your own custom JS script which is included via the theme template or somewhere ...), or if there was an option to control its placement?Cheers (+ hoping these comments are helpful!),
gpk
Comment #2
gpk commentedFinal comment for now (I hope) ...
Re. the workaround I proposed above, after deleting the variable googleanalytics_segmentation from the variables table in the database, the cache table must also be emptied for the change to take effect ...
Comment #3
gpk commentedFinal final comment ...
OK from a quick look at
__utmSetVar()it is clear that if called with an empty string then it does nothing, and shouldn't interfere with other calls (with a non-null argument) on the same page.So this was all rather storm in a teacup. Sorry! (But it would still be cool if line 63 checked for empty string OR empty array, and perhaps if the placing of
__utmSetVa()rand the custom snippet was altered as I previously mentioned! I'd do a patch but I'm already way out of my depth ...)cheers
gpk
Comment #4
ardas commentedThis problem occurs because is_array() returns true when the array is empty.
One more case - when you specified several profile fields and than turn profile.module off you will receive an error saying "Call to undefined function profile_load_profile"
I propose to change this IF statement:
to this one:
Comment #5
buddaI've used
module_inoke()now when calling the profile module function, so if the module is deactivated the GA module wont die.A recent change in CVS means the
__utmSetVar('');.only appears if there are fields to inject.Comment #6
gpk commentedThanks budda :-)
Any thoughts on the positioning of
__utmSetVar()and custom JS snippet - i.e. Google say to put it after the call tourchinTracker()Cheers
gpk
Comment #7
(not verified) commented