Problem:
Currently, when the Google Analytics module is enabled, warning messages are displayed after flushing the cache and there seems to be a conflict with Google Analytics' tokens:

Warning: strnatcmp() expects parameter 1 to be string, array given in token_asort_tokens() (line 565 of /sites/all/modules/token/token.module). Backtrace:
strnatcmp(Array, 'Last login') token.module:565
token_asort_tokens(Array, Array) 
uasort(Array, 'token_asort_tokens') token.module:525
token_get_info() token.pages.inc:97
theme_token_tree(Array) theme.inc:1142
theme('token_tree', Array) token.pages.inc:59
token_page_output_tree() 
call_user_func_array('token_page_output_tree', Array) menu.inc:517
menu_execute_active_handler() index.php:21

and

Warning: strnatcmp() expects parameter 2 to be string, array given in token_asort_tokens() (line 565 of /sites/all/modules/token/token.module). Backtrace:
strnatcmp('Last access', Array) token.module:565
token_asort_tokens(Array, Array) 
uasort(Array, 'token_asort_tokens') token.module:525
token_get_info() token.pages.inc:97
theme_token_tree(Array) theme.inc:1142
theme('token_tree', Array) token.pages.inc:59
token_page_output_tree() 
call_user_func_array('token_page_output_tree', Array) menu.inc:517
menu_execute_active_handler() index.php:21

 
To prevent a name overlap/conflict with other modules, maybe another token level could be added for Baidu Analytics' tokens, such as:
current-user:baidu_analytics:role-names.
 
This could prevent any conflicts from happening with any third party generated user tokens.
 
Duplication of tokens in this case, with similar features as the ones from Google Analytics, but with different names, isn't necessarily a problem since the module only adds two tokens.
Perhaps a better solution could be envisioned in the future, but I'm not necessarily convinced that checking whether a module is enabled or not could be a good solution. It would only fix the problem temporarily until another conflict is discovered.
 
For the moment, using a specific namespace for module's tokens would seem to be a reasonable and acceptable solution.
 
Please let me know if you would have any questions, objections, comments, suggestions, recommendations or concerns on any aspects of this bug report, I would be glad to provide more information or explain in more details.
 
Any questions, feedback, testing, changes, ideas or recommendations would be highly appreciated.
Thanks to all in advance.

Comments

dydave’s picture

Status: Active » Fixed

Quick follow-up on this bug report:

Modified module's tokens to add an additional level under Users, called Baidu Analytics, to prevent token names conflict, as suggested in the issue summary. Added a new Token Type called baidu_analytics, attached to the User Token Type and with the two tokens role-names and role-ids attached.

The tokens added by Baidu Analytics have now been changed to:

  • [current-user:baidu_analytics:role-names]
  • [current-user:baidu_analytics:role-ids]

This change seems to properly fix the issue: no more conflicts with Google Analytics tokens, no more warning messages after flushing the cache and tokens from both modules seem to be work as expected (display in token tree and replacement).

Additionally, since these tokens are now added with the specific name space baidu_analytics, there shouldn't be any more conflict/overlap issues with any other module.

Added a short inline comment to explain why this additional Token Type would be needed.

I went ahead and committed the changes against the 7.x-1.x branch at 0addcb1.

I allowed myself to mark this issue as fixed for now, but feel free to re-open it, or post a new ticket, at any time if you have any further objections with this ticket or related commit 0addcb1 (we would surely be happy to hear your feedback).

Please let me know if you would have any further comments, feedback, questions, issues, objections, suggestions or concerns on the commit or this bug report in general, I would be glad to provide more information or explain in more details.

Special thanks to @xiukun.zhou for his great help on this issue, investigating, debugging and coming up with the idea of adding the baidu_analytics token type under User to specify a "name space".
Thanks in advance to everyone for your testing, reviews, feedback and comments on this issue.
Cheers!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.