@uniformdev/context
This package provides the core functionality for Uniform's classification, personalization, and testing capabilities.
Classes
Context
- optionsContextOptions+ show child attributes
Emitted when quirk data changes.
- The event is not fired if an update does not result in at least one change to a quirk value.
Each key on the event object is a string that identifies the name of the quirk. The value for each key is a string.
Emitted when the scores are updated.
- The event is not fired if an update does not result in any score changes.
- The result is merged between session and permanent data.
Each key on the event object is a string that identifies the name of the visitor dimension. The value for each key is a number.
- fromAllDevicesboolean- If false, logout from this device ID. If true, forget all data about the visitor and their identity.
- messageLogMessage
- optionsPersonalizeOptions+ show child attributes
- optionsTestOptions- Options that control how the A/B testing process runs.+ show child attributes
- newDataContextState- New data used to updated the Context.+ show child attributes
CookieTransitionDataStore
- optionsCookieTransitionDataStoreOptions+ show child attributes
- fromAllDevicesboolean (optional)- If false, logout from this device ID. If true, forget all data about the visitor and their identity.
__UNIFORM_DATA__
) that contains the computed visitor data from the SSR/edge render. This data is injected into the first render to allow score syncing and the server to request commands be applied to the client side data store.- ServerToClientTransitionState- Client transition state was resolved.+ show child attributes
- null- No client transition state was resolved.
- commandsStorageCommands[]
- computedValueVisitorData
ManifestInstance
Coming soon.
TransitionDataStore
- optionsTransitionDataStoreOptions+ show child attributes
- fromAllDevicesboolean (optional)- If false, logout from this device ID. If true, forget all data about the visitor and their identity.
__UNIFORM_DATA__
) that contains the computed visitor data from the SSR/edge render. This data is injected into the first render to allow score syncing and the server to request commands be applied to the client side data store.- ServerToClientTransitionState- Client transition state was resolved.+ show child attributes
- null- No client transition state was resolved.
- commandsStorageCommands[]
- computedValueVisitorData
VisitorDataStore
Emitted when quirk data changes.
- The event is not fired if an update does not result in at least one change to a quirk value.
Emitted when the scores are updated.
- The event is not fired if an update does not result in any score changes.
- This is fired for any update, whether from integrated or transition storage.
forget()
on Context, which also clears the Context state.- fromAllDevicesboolean- If false, logout from this device ID. If true, forget all data about the visitor and their identity.
- commandsStorageCommands[]- If false, logout from this device ID. If true, forget all data about the visitor and their identity.
Functions
createLinearDecay
Creates a linear decay function that can be assigned to the Context. Linear decay involves reducing a score by the same amount each day the decay runs.
The following describes how decay works over time and with continuing engagement. Consider the following settings:
- Scores will decay by 10% each day (decay rate).
- The most a score will decay in a day is 95% (decay cap).
- Decay will start after 1 day (grace period).
Day | New activity | Decay | Total score | Notes |
---|---|---|---|---|
1 | 100 | 0 | 100 | No decay due to grace period. |
2 | 0 | 10 | 90 | Decay is 10% of the previous day's score (100). |
3 | 0 | 9 | 81 | Decay is 10% of the previous day's score (90). |
4 | 20 | 8.1 | 92.9 | Decay is 10% of the previous day's score (81). Decay does not apply to the new activity score. |
5 | 0 | 9.29 | 83.61 | Decay is 10% of the previous day's score (92.9). |
import {
Context,
createLinearDecay,
} from '@uniformdev/context';
const manifest = { project: {} };
const options = { decayRate: 0.1 };
const context = new Context({
manifest,
consent: true,
decay: createLinearDecay(options),
});
For more information, see the linear decay activation guide.
enableConsoleLogDrain
import {
Context,
enableDebugConsoleLogDrain,
} from '@uniformdev/context';
const manifest = { project: {} };
const level = "debug";
const options = { enableOnServer: false };
const context = new Context({
manifest,
consent: true,
plugins: [
createConsoleLogDrain(level, options),
],
});
For more information, see the console log plugin guide.
enableContextDevTools
import { Context, enableContextDevTools } from '@uniformdev/context';
const manifest = { project: {} };
const context = new Context({
manifest,
consent: true,
plugins: [
enableContextDevTools(),
],
});
For more information, see the Context DevTools plugin guide.
getEnrichmentVectorKey
Types
ContextOptions
- messageLogMessageSingle or LogMessageGroup- The message or messages that were emitted from the data store.
Called when server-to-client transfer state is loaded and contains server-side computed scores. These scores are used as a temporary shim for the current scores on the client side until score computation is completed the first time (which occurs when the current url is fed into the tracker).
Because the feed of the URL may be marginally delayed (for example in React it is in an effect so it is a second render), one render might be done with no scores unless we dropped the server scores in temporarily, resulting in a flash of unpersonalized content.
- stateServerToClientTransitionState
ContextPlugin
- contextContext- The tracker to which the plugin is being initialized for.
For information on how to create your own plugin, see the custom plugins guide.
DecayFunction
For information on how to create your own decay function, see the custom decay functions guide.
LogDrain
LogMessageSingle
Coming soon.
LogMessageGroup
Coming soon.
ManifestV2
{ "project": { "pz": { "enr": { "1": { "cap": 100 } } }, "test": { "firstTest": {} } } }
OutputSeverity
info
, warn
or error
will be logged.warn
or error
will be logged.error
will be logged.Quirks
Quirks are used to store arbirary data that is associated with a visitor. The quirks object is a set of key-value pairs where the key and value are both strings.
{
"location": "San Francisco",
"status": "Member",
"value": "10000"
}
For more information about quirks, see the classification capability.
ScoreVector
This type is used to store the scores calculated during the classification process. The object is a set of key-value pairs where the key is a string (i.e. the name of the visitor dimension) and value is a number.
{
"developer": 10,
"investment": 5,
"challenger": 3
}
For more information about visitor dimensions, see the classification capability.
Severity
Each message that is sent to the logger has a severity level. Whether the logger writes the message to the log depends on the output severity assigned to the logger.
info
, warn
or error
will be logged.warn
or error
will be logged.error
will be logged.StorageCommands
Property value | Data type |
---|---|
modscore | object Changes the visitor's permanent score for a given dimension. + show child attributes |
modscoreS | object Changes the visitor's session (time-based) score for a given dimension. + show child attributes |
consent | boolean Changes the visitor's storage consent setting. Setting consent to false will trigger deletion of any stored data for the visitor. Scores are still collected in-memory when consent is false; just not persisted. |
setquirk | object Sets a permanent quirk key and value for the visitor. + show child attributes |
settest | object Sets a specific variant as being this visitor's variant on an A/B test. + show child attributes |
identify | string Identifies the visitor as being a specific unique identifier. This only has an effect when using an external cross-device transition storage system. You cannot read the identified visitor ID back from the storage system once it is set. |
setcontrol | boolean Sets whether the current visitor is in the personalization control group (will not be exposed to personalization or gather classification data; WILL see A/B tests). In most cases this should not be sent as the membership is computed automatically for visitors. This command is intended mostly for diagnostics and testing purposes. |
Tests
This type represents the A/B test variants that were displayed to the visitor. The object is a set of key-value pairs where the key (i.e. the name of the test) and value (i.e. the name of the variant) are both strings.
{
"promo": "full-color",
}
For more information about testing, see the A/B testing capability.