Google has deprecated a tracking feature _setVar() and now I'm planing to upgrade to Custom variables. As the implementation will become very generic and makes use of tokens I'm searching for an upgrade path for previous profile tracking features for the reason that I do not like to reduce functionality...

While searching around I was not able to find a token with the current user roles!? Is there one or any module that add's this token or are we able to add this token to the token module?

As d.o also use the group membership for tracking purposes it may be pretty important.

Comments

Dave Reid’s picture

There is not currently any [user:roles] token. Suggestions as to what output that token should generate are welcome.

hass’s picture

Thank you very much for quick feedback. I suggest a comma separated list of all roles a user is a member of. The data should already be in the $user object... :-)

hass’s picture

@Dave: For now I have created a googleanalytics.tokens.inc and added [user:roles] how I need it. I hope this will not cause collisions if it will be added in a different way.

The missing D7 tokens docs need some *LOVE*... trial and error only :-(

Dave Reid’s picture

Token API docs are already provided by core, and several core modules implement them, showing how to do it...

Dave Reid’s picture

hass’s picture

Well, but than you need to expect an API change first... I was pretty lost with the documentation links at http://drupal.org/handbook/modules/token and http://drupal.org/handbook/modules/token/update/6/7. None of these docs tells me something about the changed API and how it was changed (upgrade docs). Core modules have been helpful, but the documentation links above need love and/or more pointers. My DX was bad, sorry. :-)

hass’s picture

Title: 'Roles' token like [current-user:roles] and [user:roles] available? » Add 'Roles' token like [current-user:roles] and [user:roles]

Changing title

Dave Reid’s picture

FYI this was originally won't fixed with #162502: Token for user roles

hass’s picture

When I implemented [roles] i thought it may be not the best name... well, I may need to change the placeholder name.

hass’s picture

I decided to change the names in GA to:

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

I wish I could have been able to use [current-user:role:names], but this seems not working if there is no [current-user:role] or at least I was not able to get it working.

Dave Reid’s picture

I am getting close to add this by way of #1047740: Add an [array:*] token type and a [user:roles] token where the tokens you would want are [current-user/user:roles] would output 'authenticated user, administrator' and [current-user/user:roles:keys] would output '2, 3'.

Dave Reid’s picture

Status: Active » Closed (duplicate)

Officially merging this issue into #1047740: Add an [array:*] token type and a [user:roles] token since the [user:roles] token provides a good basic use case for the array token type.

liquidcms’s picture

too bad not a role token that doesn't included authenticated user; since that role is rarely ever useful to state.