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 event() call. They're ideal for context that applies broadly across a session, such as a campaign_id, an experiment variant, or a membership_plan you want carried onto many events at once.
Common values passed as Global Attributes include:
- campaign_id
- experiment
- membership_plan
- referral_code
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 the event() method
- Automatically captured system events, such as install, update, app_launch, and session_start
Availability
Global Attributes are supported on Web, Android, and iOS. This page covers the Android SDK; the Web and iOS SDKs expose the same capability through their own methods.
Step 1 — Configure the persistence mode
Before using Global Attributes, configure the persistence mode in your app's Application class. Do this before calling NVECTA's register method, so the SDK can initialise and manage Global Attributes correctly.
NVECTA supports three persistence modes:
| Mode | Survives app restart | Cleared when | expiryInDays |
|---|---|---|---|
| Memory | No | The app is restarted or the process is terminated (lives only while the app process is running) | Not used — pass 0 |
| Session (default) | Yes | The current app session ends | Not used — pass 0 |
| Persistent | Yes | The configured cookieExpiryDays value elapses | Required |
- Memory stores attributes only while the app process is alive.
- Session keeps attributes for the current app session and clears them automatically when the session ends.
- Persistent is the only mode that stores attributes on the device, so they remain available after the app is closed or restarted.
Syntax
NotifyVisitorsApi.getInstance(applicationCentext).globalAttrsPersistOptions(NVGLobalAttrsPersistenceType.PERSISTENT, (int) expiryInDays)
expiryInDays applies only to Persistent mode
Use 0 for Memory and Session modes.
Example
NotifyVisitorsApi.getInstance(applicationCentext).globalAttrsPersistOptions(NVGLobalAttrsPersistenceType.PERSISTENT, 10)
NotifyVisitorsApplication.register(applicationCentext, BuildConfig.NV_BRAND_ID, BuildConfig.NV_SECRET_KEY)
Step 2 — Setting global attributes
Use this method to define the Global Attributes that should be included with your events.
NotifyVisitorsApi.getInstance(context).setGlobalAttributes(NVGlobalAttributes.Builder()
.put("campaign_id", "SUMMER_2026")
.put("membership_plan", "Premium")
.build())
After setting the above Global Attributes, both auto-captured and custom events will automatically include:
{
"campaign_id":"SUMMER_2026",
"membership_plan":"Premium"
}
- If you define Global Attributes in the Application class, they are automatically attached to system events such as install, update, app_launch, and session_start. Defining them during application startup ensures these events include the required attributes and prevents them from being missed.
- You can also call this method from anywhere in your application to add, update, or overwrite Global Attributes for subsequent events.
Updating global attributes
Use setGlobalAttributes() to add new Global Attributes or update the values of existing ones.
NotifyVisitorsApi.getInstance(context).setGlobalAttributes(NVGlobalAttributes.Builder()
.put("membership_plan", "Gold" )
.build())
Only the specified attributes are added or updated. Any existing Global Attributes that are not included in the request remain unchanged.
Removing global attributes
Remove a single attribute by key with removeGlobalAttribute():
NotifyVisitorsApi.getInstance(context).removeGlobalAttribute(“campaign_id”)
The removed attribute will no longer be included in future events.
Clear all Global Attributes with clearGlobalAttributes():
NotifyVisitorsApi.getInstance(context).clearGlobalAttributes();
After clearing, none of the previously defined Global Attributes will be attached to future events.
Good to know
- Global Attributes are best suited for values that should be sent with multiple events, such as attribution data, experiment IDs, user context, or checkout information.
- If an attribute is relevant to only a single event, pass it directly in the attributes parameter of the event() method instead.
- Use distinct names for global attributes and event attributes to keep your data clean and unambiguous.
Updated 2 days ago
