I would like to pass a user profile variable (ex. Job Title) to an analytics tool. The issue I'm facing is that the user profile variables are cached so the user profile variables are passed are always for the user that cached the page (rather than subsequent visitors).

The solution I've pursued is to enable the authcache_user module and try to pass the desired user profile fields (in hopes of eventually passing these on to the analytics tool):

.module file

function mymodule_init() {
authcache_p13n_add_setting(array('#setting' => 'user'));
drupal_add_js(drupal_get_path('module', 'mymodule') . '/mymodule.js');
}

I'm then simply printing these with JS (for now) to verify the uncached data is visible:

(function ($) {
  Drupal.behaviors.mymodule = {
    attach: function (context, settings) {
      if (settings.authcacheUser) {
console.log(settings.authcacheUser.name);
console.log(settings.authcacheUser.uid);
      }
    }
  };
}(jQuery));

The issue I'm facing is that I can only view the uid, name and email. I'm stumped on how I would I go about adding other user profile variables such as custom fields? Any help would be appreciated...Thanks!

CommentFileSizeAuthor
#11 auc_customuser.tar_.gz611 bytesznerol
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sethmac created an issue. See original summary.

sethmac’s picture

Title: Allowing User Fields to be persononalized » Allowing User Fields to be pesonalized
sethmac’s picture

Issue summary: View changes
sethmac’s picture

Issue summary: View changes
sethmac’s picture

Issue summary: View changes
sethmac’s picture

Issue summary: View changes
znerol’s picture

You might want to try implementing hook_authcache_p13n_setting_alter and add the property in question to the #arguments key of the user setting. Not sure whether that works with custom fields though.

Another option is to use cookies as described in #2617684-9: scripts per user on <header> for cached pages.

sethmac’s picture

I attempted to add the properties (even just removing existing mail field) but couldn't get the alter to have any effect. Very likely could be user error.

The cookie approach does seem to be the most promising though I hope to pass quite a few values so I'm not sure it will be the most efficient way unless I just store the uid and do a lookup and get the info back to analytics JS. Just thinking aloud, but this is a start. Thanks

znerol’s picture

I forgot to say that you need to rebuild the router after changing code (flushing the cache is not enough). Navigate to Administration » Configuration » System » Authcache » Personalization » Frontcontroller and click on the Rebuild routes button at the bottom of the page.

sethmac’s picture

Hmm..no luck after the rebuild. Still just see mail, uid and name in the object.

znerol’s picture

FileSize
611 bytes

It seems to me that this should be working. Though it does not with custom fields :/

Custom fields require the entity system and that depends on hooks and therefore in order to support custom fields in a generic way, the setting would need a full bootstrap. Maybe the setting renderer class could be provided in two versions - a fast one and one with support for fields.

sethmac’s picture

Was able to get it working with the cookie as referenced. Still exploring the other fields. Thanks for being so responsive.

znerol’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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