Posted by jmesam on October 20, 2009 at 8:43pm
| Project: | Google Analytics |
| Version: | 6.x-3.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | major |
| Assigned: | hass |
| Status: | closed (fixed) |
Issue Summary
Hi!
Today Google Analytics team announced a new set of features. There are 2 of them that could be included in future releases of GA module:
1. Expanded Mobile Reporting: Google Analytics for mobile
2. Multiple Custom Variables: more info
I'm very excited about multiple custom variables, imagine the power of drupal plus the level of segmentation we could get with all those variables...
Comments
#1
Oops, I forgot to mention that Google Analytics for mobile link it is a compress file (zip).
More info about Multiple Custom Variables: http://code.google.com/intl/es-ES/apis/analytics/docs/tracking/gaTrackin...
#2
Google Analytics for mobile!
#3
Mobile Apps tracking seems not related to Drupal, see http://code.google.com/intl/en/apis/analytics/docs/tracking/mobileAppsTr.... It's more for Apps on Phones...
Multiple custom variables sounds very helpful and promising...
#4
#5
Google Analytics for mobile it is not the same that Mobile Apps tracking, GA for mobile it's for website not apps, and consists of server-side tracking for mobile sites that use JSP, PHP, ASP.NET, or Perl as their server-side language. This allows tracking on mobile websites that receive traffic from phones that do not support the JavaScript-based tracking usually used by Google Analytics.
#6
Ah, ok. Lets split this in two issues, please.
#7
Google Analytics for Mobile should not be implemented on the pages which already have ga.js. See known issues in the readme.pdf
More important, GA for Mobile adds server load, therefor, it should be used only on the pages that are for mobile access/traffic. Otherwise, too much overhead.
Having said that, it's very hard for GA module to decide whether to generate ga.js or to include php.snippet on a specific page, since GA module won't know how a page is accessed.
But, we have Services Module, which is used for mobile and flash access. It would make much sense, if GA module could develop a Services include, so the Services Module could call GA for Mobile.
#8
We can use the browser detect module (cannot remember the module name) and only use the mobile GA tracking in such a case. I'm often surfing on sites with my iPhone and I think there are good reasons not to limit this to directories... Never thought much about this yet, but at least the iPhone shouldn't have issues and require a real change to logic. Not 100% sure, but it sounds like this only stops downloading of the JS stuff and that's it. This wouldn't add much more load the ga module as today.
We should nevertheless split this in a new case. This one here for the setVar stuff (we need a patch), and the other case for implementing the (optional) mobile feature.
#9
I'm really asking me who is using a browser that is not able to use javascript... iPhone, Windows Mobile can execute JavaScript. Not sure about Blackberries, but they should also work or the internet on mobile devices makes really no sense... many years the mobile phone manufacturers thought they can get us on to bad WAP bad stuff... but the customers haven't used it - why should we waste time for a feature used by 0.000001% (I may have missed a few more zeros) of the internet users???
#10
All browsers on modern phones support JS; GA for Mobile is developed for service based application or other cloud computing sites; the remote client access those remote services Not through browsers, therefore javascript won't be executed. That's where the GA for Mobile should come in and shift the burden to the server. As I proposed earlier, it would make more sense, if GA module could make a GA for Mobile include file for Drupal Services Module.
#11
This is not logic. Cloud sh** or not the JS ga tracking works. I do not see any real world drupal example...
#12
Hi,
This thread seems to have gone off topic a bit but to bring it back to multiple variable support...
Does anyone know if there are any plans to add support for _setCustomVar? I've seen a number of requests for adding hooks to provide more flexibility to the current _setVar implementation. I think with _setCustomVar it's essential that it's hook based - I can't see that the "one size fits all" approach currently employed for _setVar will ever work for _setCustomVar.
I need this new feature fairly quickly. Would there be any interest in me providing a patch to add support for this? If nothing else at least it might start the ball rolling....
#13
Hi idontknowtheanswer,
A patch to start the ball rolling on Custom Variables support for GA sounds great.
I'm not sure which variables you were thinking of tracking.
Reading this page by google:
http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVari...
Some Potentials i can think of are:
"Page-level Custom Variables" would fit well as Taxonomy of the drupal node being viewed.
"Visitor-level Custom Variables" could parrallel user role.
As a convention i'd suggest maybe making the custom variable name the same as the drupal database table name for consistency across installations.
So the role variable would look something like this when triggered:
pageTracker._setCustomVar(
2,
"role",
"anonymous user",
3
);
You'd want to loop through the role table to pick up all potential custom user defined roles.
Just brainstorming pseudo code. Hope someone gets round to this one as it will be powerful. (if not i hope to soon myself.)
#14
This may be some good ideas, Thank you for sharing them.
Non of the custom variables seems to work out of the box only by pushing the data to google if I have read the docs correctly. This would be a major issue with Custom Variables as the user needs to configure Google Analyics (on google.com) in such a fine grained way only to get this working that I do expect hundreds of thousands of support requests in here... If we get this in, we need to write a very detailed documentation how to configure Google before a release having this features.
It's comparable to how many people followed the Google tracking code documentation and tried to enter the standard GA code to the advanced JS script boxes in past. The requests have dropped to 0 after I've added some basic form validation to catch this.
We need to brainstorm about a list of what to track before we start implementing.
1. Tracking taxonomy terms sounds like a great idea to me. I also need this myself, too.
#15
I'm thinking about implementing Google's new custom variables like this:
1. Adding the appropriate code to the "Custom JavaScript code" section ("Code snippet: before") of admin/settings/googleanalytics - something like:
pageTracker._setCustomVar(1, "variable1", Drupal.settings.custom_module.variable1, 1);pageTracker._setCustomVar(1, "variable2", Drupal.settings.custom_module.variable2, 1);
2. Writing a small custom module that will set the values of variable1 and variable2 using the drupal_add_js() function.
Does this seem like a reasonable plan?
-mike
#16
+1
#17
subscribe
re #15, i think a simple table in the setting page will do the job, as GA only allow 5 custom var per page
also, that table need token support, to pop taxonomy there, if applicable.
#18
did a patch
#19
need review state
#20
At least uninstall is missing and t() strings need to use placeholders. I have not reviewed the logic.
#21
uninstall added. t() placeholder added
#22
Has anyone successfully sent taxonomy data from node hits to Google Analytics with this patch?
#23
re #22
you have to set correct token in GA module settings in advance settings -> custom variables
i use sth like vocab:test as name, value as [term]
make sure you have token module installed.
#24
i have further tested on my blogging site, which custom var works with only node pages, but only top term due to token limitation.
if you need all taxonomy listed in custom var, you may look at http://drupal.org/node/185446 for token workaround. (untested)
#25
Subscribing.
#26
I applied the patch on comment #21, and I noticed that the custom variable is called after _trackPageview(). And it should be called prior _trackPageview() (see the docs)
Your patch output is:
var pageTracker = _gat._getTracker("UA-xxxxxxx-x");pageTracker._trackPageview();
pageTracker._setCustomVar(1,"name","value",3);
and it should be:
var pageTracker = _gat._getTracker("UA-xxxxxxx-x");pageTracker._setCustomVar(1,"name","value",3);
pageTracker._trackPageview();
The content taxonomy module allows token per vocabulary.
#27
re #26, thx for the catch
#28
There are many code style issues, bugs in t() function and drupal_to_js is missing and missing periods in sentences.
#29
coding style passed coder module.
t() fixed, periods, too.
what do you mean by "drupal_to_js is missing"?
#30
Ok, code style looks better, but don't use double qoutes in t() if not required.
You allow users to input some values. This values are added to the page content without being filtered for arbitrary code. Only add a double quote to such a value and you will end up with js errors. Drupal_to_js prevent this and surround the code with double qoutes...
Does the code apply to D7 1.x, too? We also need a patch for the async version 6.x-3.x (not avaiable yet)
#31
#32
Example that allows code injection (security bug):
+ else {+ $custom_var .= 'pageTracker._setCustomVar('. $i .',"'. $custom_var_i .'","'. variable_get('googleanalytics_custom_var_'. $i .'_value', '') .'",'. variable_get('googleanalytics_custom_var_'. $i .'_scope', '') .');';
+ }
Secure code with filtered user input:
<?php$custom_var .= 'pageTracker._setCustomVar('. $i .', '. drupal_to_js($custom_var_i) .', '...
?>
#33
lucky you provide example...
t("") fixed.
drupal_to_js() fixed
p.s. this time netbeans is used to create patch, let me know if the format does errors
#34
There seems to be a collision problem... as setVar() is deprecated. Therefore we also need to use the _setCustomVar() for segmentation tracking. There is also a request in #378550: Segmentation by Organic Groups for OG. If I understood this _setCustomVar() correctly, we may loose the first two "slots" for this features and we can use max 5 per request..
pageTracker._setCustomVar(1, "Segmentation", "Foo, bar", 1);pageTracker._setCustomVar(2, "OG Groups", "group1, group2, group3", 1);
On sites where we do not have OG installed we only loose one slot, with OG we loose two slots... as more modules as we get as fewer slots are available for custom code snippets and this could also be dynamic... not sure how we should solve this with the above static configuration.
Any ideas?
#35
dynamic configuration still cannot solve the "5 slot limit" problem?
i think we can provide api to other modules, but the api can only warn user if system need more than 5 slots, and thus ask user to disable some?
and i do not know how OG will make use of custom vars, but custom vars mainly focus on user related vars, otherwise, event tracking should be used. http://code.google.com/intl/zh-TW/apis/analytics/docs/tracking/gaTrackin... (in recommended practices)
#36
Subscribe
#37
Subscribe
#38
The last submitted patch, ga_custom_var_4.patch, failed testing.
#39
Fixed Unix LF's and the wrong path's in the patch.
#40
@joetsuihk: #35, OG group memberships are used based. The implementation idea provides a list of the users group membership. By this statistics you can gain the popularity of groups... :-)
#41
I do not plan to commit code to 2.x. Needs an API upgrade for D6 3.x and D7.
#42
How bad that there is a 64-byte character limit for the name and value combined. Not sure if we need to cut off or Google does it. I guess it could have something to do woth the URL lenght... :-(
#43
Also remember that the variables and its values has to be url encoded.
I have found this article about it:
#44
I'm considering using this, so I've updated the patch for the 6.x-3.x branch. I didn't see #42 and #43 until just now--I'll update my version of the patch with those things in mind shortly.
#45
I have added a patch to #916314: Segmentation requires Custom variables update that needs reviews very soon. Would be great to see you there, too.
#46
I've updated my patch to reflect #42 and #43, and re-rolled it against DRUPAL-6--3. In summary, this patch adds:
Do you think this we can get this into the module? Would it help if I also provide a D7 patch?
#47
subscribe
#48
Nothing goes in before there exists a D7 patch.
#49
I have tested the patch provided in #46, it works perfectly. I'm using the custom variables with token, but when a token is empty the custom variable get the token name:
_gaq.push(['_setCustomVar', 1, "section", "[node:vocab:2:term]", 3]);Is there a way to check when a token is empty and hide its value?
#50
+ $form['advanced']['custom_var']['#description'] .= t("<p>If you install the !token module, you can use Tokens as custom variable values.</p>", array('!token' => l('Token', 'http://drupal.org/project/token')));Never use P inside translatable strings and never use l() to for placeholders.
#51
@hass -- Here's a fresh patch for Drupal 6, and a new one for Drupal 7. I've fixed instances where I used <p> inside of t(), and where I used l() in placeholders. I've also updated the token_replace() call so that it provides global and user tokens as well as node tokens.
@jmesam -- Token in Drupal 6 won't remove empty tokens, but token_replace() in Drupal 7 does provide an option to clear empty tokens, which I am now using in the D7 version of this patch.
#52
The last submitted patch, ga_custom_var-d7-609892-51.patch, failed testing.
#53
TW urls are not really usefull for non TW people... For labels, uppercase first word and all other words lowercase, please.
#54
Marked #378550: Segmentation by Organic Groups as a duplicate of this issue.
#55
Also marked #916314: Segmentation requires Custom variables update as duplicate as we need to upgrade the profiles segmentation with
_setCustomVar()as per Googles recommendation. Case #916314: Segmentation requires Custom variables update has a patch where we can use parts of it for an upgrade hook if profile segmentation is already configured.#56
subscribing
#57
#58
#51: ga_custom_var-d7-609892-51.patch queued for re-testing.
#59
Currently working on a better user interface...
#60
Can someone shed some light on me please, how the custom variable feature make any sense without having tokens module installed?
#61
Need feedback for #1012190: How to block tokens with personally identifying information?
#62
We also need #1012202: Add 'Roles' token like [current-user:roles] and [user:roles].
#63
Removed
#64
Here is an updated D7 patch. It adds:
1. An user interface based on a table (*important* usability impovement)
2. Input validation if a value in name/value field is missing
3. Input validation now blocks illegal tokens with personal identifying information (may need improvement and testing)
4. Only one setting variable for all custom variables (less DB stress)
5. A few textual improvements.
6. Other minor code style issues fixed.
7. Added token tree view
8. Added DEPRECATED comment to segmentation (segmentation will be removed, after the open to-do's are solved)
Open to-do's:
1. #1012202: Add 'Roles' token like [current-user:roles] and [user:roles] has been confirmed not to be available (will currently break upgrade path for very many people). May add
googleanalytics:user:rolesandgoogleanalytics:current-user:rolestokens to GA module to archive the goal.2. Implement an upgrade path for "User roles" to custom variables
3. Profile module is deprecated in D7, #691078: Field tokens needs testing
#65
Created a tokens file with
[user:roles]and [current-user:roles].#66
Solved the remaining issues. This patch is really big and does not remove profile segmentation stuff for now.
1. Upgrade path implemented
2. Google Analytics module provides [user:roles] and [current-user:roles] with comma separated item list.
#67
This patch also removes the profile segmentation UI if not in use.
#68
Committed to D7, thank you very much for your help.
#69
#70
Follow up in #1017384: Fix use of token_replace()
#71
D6 patch attached. This also requires an additional upgrade path patch for D7 update_7000.
#72
Missed the readme and an token check in update hook.
#73
#74
This needs fixes to token handling. Because the token replacement only replaces node + global token types, the use of array('all') is incorrect here.
#75
Well, I also am not sure exactly what happened here. Looks like token support was turned optional, but the code is pretty ugly. :/
#76
I don't like the how, too. Have not found a clean way yet without depending ga on token. I'm open minded to better ideas and fighting with me for 2 days if i make ga dependent on token to cleanup the code, but many people may not need custom variables... Not sure where to go
#77
#78
Why can i not use 'all' in the form validation? I may like to validate all tokens and not only node tokens??? I'm confused about the parameter...
#79
You can't use array('all') because that will show all token types including comments, taxonomy terms, vocabularies, etc. plus the global token types. But you're only performing token replacement with array('node' => $node). So you're not providing a comment object, or a term object, or a vocabulary object (which is correct), so therefore those types of tokens won't be able to be replaced.
#80
#81
@Dave: For save validation of the custom variable values I need token module. This code is ugly, but if you know a better way I'm very open minded. The bad is if
'#element_validate' => array('token_element_validate', 'googleanalytics_token_element_validate'),is used in a form element and the token module is not installed it throws me a 'token_element_validate' function not found error on form save. My ugly code in D7 works fine, but for D6 it is much more ugly as core does not have token_scan() function and I need to run two different validation ways or duplicate token_scan().At least D6 element validation is horrible. Two different validation ways... D6 code has not yet committed. However if you have a better/cleaner idea for element validation without token installed - let me know, please!
#82
Simple
<?php
$form['myelement'] = array(
'#type' => 'textfield',
'#element_validate' => array('mymodule_function'),
);
if (module_exists('token')) {
$form['myelement']['#element_validate'][] = 'token_element_validate';
}
?>
Huh?
#83
Yeah, this looks cleaner :-)
I mean the much more ugly D6 code has not committed. I will post here if it's ready.
#84
Ah, I thought you were referring to the Token module for D6 code. :)
#85
@Dave: This is the D6 patch and it validates with two logics the same values. The used logic depends on token enabled/disabled. Only for the reason that token_scan() is not available if token is not installed in D6. I dislike it, but it seems to be the only way to make sure nobody can circumvent the validation process.
#86
Automatically closed -- issue fixed for 2 weeks with no activity.