Browse docs

setAttributes()

Add or update custom attributes on a visitor without re-identifying.

Use setAttributes() to add or update custom attributes on the current visitor without re-identifying them. It is the right call whenever you learn something new about a visitor — their plan, seat count, lifecycle stage — but their identity has not changed. It works for visitors you have already identified and for visitors who are still anonymous, so you can enrich a profile before you ever know who someone is.

Signature

setAttributes(attributes)

Parameters

Parameter Type Description
attributes
required
object An object of key/value custom attributes to set on the current visitor. Each value may be a string or a number. Keys that already exist are overwritten; new keys are added. The visitor's identity is never changed.

Example

Pass a plain object of the attributes you want to set. Strings and numbers are both supported.

NudgeVisor.setAttributes({
  plan: 'Enterprise',
  seats: 25,
});

setAttributes vs identify

The two methods write to the same underlying attribute store, but they answer different questions:

  • identify() sets who the visitor is — an external ID plus the reserved name and email traits — and any custom traits alongside them.
  • setAttributes() only updates custom attributes. It never sets or changes the visitor's external ID, name or email, and it never re-identifies the session.

The traits object on identify() is the same mechanism as the object you pass here: on identify(), name and email are reserved and everything else becomes a custom attribute, whereas with setAttributes() every key is a custom attribute. Use identify() when you have an identity to attach; use setAttributes() when you only want to enrich an existing profile.

// identify() sets WHO the visitor is
NudgeVisor.identify('USER_ID', {
  name: 'Ada Lovelace',
  email: '[email protected]',
});

// setAttributes() only enriches them — identity is untouched
NudgeVisor.setAttributes({
  plan: 'Enterprise',
  seats: 25,
});

Anonymous enrichment

You do not have to wait for login to record useful context. Because setAttributes() does not touch identity, you can call it on an anonymous visitor to capture signals such as the page they arrived from or a trial plan they selected. When you later call identify(), the attributes you set while the visitor was anonymous are retained on the now-identified profile.

// No identify() call yet — the visitor is still anonymous.
// You can still attach what you know about them:
NudgeVisor.setAttributes({
  signupSource: 'pricing-page',
  trialPlan: 'Growth',
});

Where attributes show up

Every custom attribute you set appears on the visitor's profile in the dashboard and is available for building segments and filtering visitors. See Attributes & segments for how attributes drive segmentation, and Identifying visitors for the wider picture of how anonymous and identified profiles fit together.

Related