Global Attributes
Global Attributes are key–value pairs you set once and NVECTA automatically attaches to the events that follow — so you don't have to repeat them in every nv('event', …) call. They're ideal for context that applies broadly across a visit, such as a campaign ID, an A/B experiment variant, or a traffic source you want carried onto many events at once.
Prerequisite
This guide assumes you're familiar with System Events and Custom Events. If not, start with the Tracking Events guide.
Which events they apply to
Once set, global attributes are automatically included on:
- All Custom Events you track with nv('event', …)
- Static events
- The session_start and page_view system events
Other auto-captured system events are not enriched with global attributes.
Availability
Global Attributes are supported on Web, Android, and iOS. This page covers the Web JavaScript SDK; the mobile SDKs expose the same capability through their own native methods.
Setting global attributes
nv('setGlobalAttributes', { campaign_id: 'QA123', experiment: 'A' });
- You can call this any time after the SDK script has loaded — including a few seconds after page load.
- Calling it again merges the keys you pass into the existing set: new keys are added, existing keys are updated, and keys you don't mention are left untouched.
Once set, the attributes ride along automatically:
nv('setGlobalAttributes', { campaign_id: 'QA123', experiment: 'A' });
nv('event', 'Added To Cart', { product_id: 'P1' });
// "Added To Cart" is sent with product_id, campaign_id, AND experiment.
Removing global attributes
Remove a single attribute by key:
nv('removeGlobalAttribute', 'campaign_id');
// Only campaign_id is removed; any other global attributes remain.
Clear all global attributes:
nv('clearGlobalAttributes');
Persistence: how long they last
How long a global attribute survives is controlled by a persistence mode. The default is session.
| Mode | Survives refresh | Shared across tabs | Cleared when | Cookie |
|---|---|---|---|---|
| memory | No | No | On any refresh or navigation (lives only for the current page view) | None written |
| session (default) | Yes | Yes | When a new session begins (typically after a period of inactivity, per your brand's session settings) | Yes (nvga) |
| persistent | Yes | Yes | After cookieExpiryDays elapses | Yes (nvga) |
- memory keeps attributes only for the current page view and never writes a cookie.
- session and persistent are cookie-backed, so their values are shared across tabs of the same site (a new tab or a refresh will still have them).
- persistent is the only mode that survives closing the browser and crossing a new-session boundary; it lasts until cookieExpiryDays is reached.
Choosing a persistence mode
There are two ways to set the mode.
Option 1 — In your integration code (before init)
Add it to your notify_visitors.options({ … }) call, before notify_visitors.init():
notify_visitors.options({
globalAttributesPersistence: {
type: "session", // "memory" | "session" | "persistent"
cookieExpiryDays: 30 // used only when type = "persistent"
}
});
Option 2 — Any time after the script loads
Assign the property directly. This is a property assignment, not a function call. For best results, set it right after the SDK script loads.
notify_visitors.globalAttributesPersistence = { type: "memory" };
For persistent mode, include cookieExpiryDays:
notify_visitors.globalAttributesPersistence = { type: "persistent", cookieExpiryDays: 30 };
The mode is per-page — it is not "sticky"
Set the mode on every page where you want a non-default behavior. It does not carry forward to the next page load on its own. Any page that doesn't set a mode uses session by default — even if an earlier page in the same visit set something else.
Invalid values are safe
If type isn't one of memory / session / persistent, the SDK silently falls back to session without throwing an error.
Switching modes on the same page
You can change the mode on an already-loaded page, without a refresh — the change takes effect immediately, including updating the cookie's lifetime.
session ↔ persistent share the same stored value. Switching between them keeps the current attributes and only changes how long they live — you don't need to re-set them:
- session → persistent immediately extends their lifetime (they'll now survive a browser close).
- persistent → session immediately shortens it back to session length.
memory is isolated. Values set in memory mode never touch the session / persistent cookie. Switching into memory and setting values won't overwrite your stored value; switch back out and the earlier value reappears untouched — regardless of the order in which you switch.
// session (default) — set a value
nv('setGlobalAttributes', { same_page_val: 'SP1' });
// switch to persistent, no refresh, no need to re-set the value
notify_visitors.globalAttributesPersistence = { type: "persistent", cookieExpiryDays: 30 };
nv('event', 'Test');
// same_page_val is still attached — and now survives a browser close.
Good to know
- Use distinct names for global attributes and event attributes to keep your data clean and unambiguous.
- session and persistent modes store data in a cookie (nvga) on your site's domain — account for this in your cookie-consent disclosures where applicable.
Updated 5 days ago
