Personalization for Logged-in Users - Accelerate Documentation

Personalization for Logged-in Users

Logged-in users can be targeted with richer context when your site updates endpoint data with authenticated-user attributes.

When to use it#

Use logged-in personalization when role, account status, membership tier, or editorial context should change the content shown to an authenticated visitor.

Implementation model#

Audience criteria always match against endpoint data stored in the visitor's browser. That keeps personalization fast and available to new users without storing endpoint state in WordPress. When you want to target logged-in user data from the WordPress database, register the field and inject the value into endpoint data.

Register attributes with Accelerate#

Register each custom data attribute so it appears in the audience builder:

text
<?php

Audiences\register_field(
  'endpoint.User.UserAttributes.IsSubscribedToNewsletter',
  'Is Subscribed to Newsletter',
  [
    'options' => [
      'yes' => 'Yes',
      'no' => 'No',
    ],
  ]
);

This adds the field to the audience builder:

Audience builder interface showing a custom field

Filter endpoint data#

Once the field is registered, inject the backend value into endpoint data. For a logged-in user's is_subscribed_to_newsletter user meta key:

text
<?php

add_filter( 'altis.analytics.data', function ( array $endpoint ) : array {
  $endpoint['User']['UserAttributes']['IsSubscribedToNewsletter'] = get_user_meta( get_current_user_id(), 'is_subscribed_to_newsletter', true ) ? 'yes' : 'no';
  return $endpoint;
} );

When the user meta value changes, the endpoint data stored in the viewer's browser can update. Any update to endpoint data can change which audience the visitor matches.

Frontend endpoint update#

You can also populate endpoint data from JavaScript:

text
Altis.Analytics.onReady(() => {
  Altis.Analytics.updateEndpoint({
    attributes: {
      role: ['subscriber'],
      plan: ['pro']
    }
  })
})

Avoid sending secrets or unnecessary personal data. Only send attributes needed for segmentation and measurement.