Activity analyzers
Run your own code on each activity before it is stored, to reformat, enrich, or clean it.
Your goal
Transform activities on the way in with logic that no declarative rule can express - reshaping a payload to fit your schema, enriching events from a catalogue, filtering what you do not want.
Expected outcome
Activities stored in the shape your schema expects, with enrichment applied consistently for every activity on the channel.
What an activity analyzer is
An activity analyzer is a plugin that lets you modify an activity on the fly before it is stored. It runs as part of the processing pipeline - at step 3, after event rules - for every activity of the channel it is associated with.
It is useful for:
Reformatting data - adapting the ingestion data model to the datamart schema.
Enriching events - for instance fetching product information from a product ID.
Improving data quality - filtering unwanted events, matching input values to standard catalogues, parsing URLs into categories.
Filtering out unwanted traffic - such as browser bots, by discarding the whole activity.
Analyzers are attached to a channel, where they appear as visit analyzers. See Channels.
What it can and cannot change
Can
Add, remove, and modify events; add and modify properties; reshape the activity object; discard the whole activity.
Cannot
Modify the identifiers passed in the incoming activity.
The contract
An activity analyzer has a single endpoint to implement.
It is called every time an activity is processed. The analyzer receives an activity and responds with a new activity, or asks the platform to discard it.
activity_analyzer_id
String
The ID of the analyzer instance to use. Use it to retrieve the instance properties.
datamart_id
String
The ID of the datamart.
activity
Object
The UserActivity object to analyse.
In most cases the plugin responds with the modified activity object to store:
To have the platform discard the activity instead of storing it:
On an unexpected error:
Dropping an activity
Responding { "status": "drop" } with an HTTP 200 tells the platform not to store the activity. A drop is a successful response: the call is not retried, no error is recorded against your plugin, and the instance's error recovery strategy does not apply.
The activity is not stored in the datamart, and triggers neither goals, automations nor analytics.
The activity analyzers placed after yours on the same channel are not called.
The Plugin SDK call and the exact status value are in Build an activity analyzer.
Error recovery strategy
Each instance carries an error recovery strategy, chosen when you create the instance in Navigator, under Settings > Datamart > Activity Analyzers. It decides what happens to the activity when the plugin fails.
STORE_WITH_ERROR_ID
The activity is passed unchanged to the next activity analyzer.
STORE_WITH_ERROR_ID_AND_SKIP_UPCOMING_ANALYZERS
The activity is stored without the failing analyzer's changes, and is not passed to the following analyzers.
DROP
The activity is not stored.
The strategy only applies when the plugin fails. An activity your plugin deliberately drops never goes through it, whatever the strategy.
Reading the instance context
Plugin code should not hard-code configuration. Use the activity_analyzer_id from the incoming request to fetch the instance and its properties:
The first returns the instance - its name, organisation, plugin ID, group ID, and artifact ID. The second returns the properties configured on it, each with a technical name, a value, a type, an origin, and whether it is writable.
This is what lets the same plugin behave differently per instance. See Plugin architecture for the instance model, and Build an activity analyzer for developing one.
Choosing between the options
Extract a value from a URL, copy a property into the origin, derive an identifier
An event rule - declarative, no code.
Rename a custom event to a predefined one, for analytics only
An event transformation - no code, but analytics-only.
Anything requiring logic, an external lookup, or arbitrary reshaping - everywhere
An activity analyzer.
Verify
The
ACTIVITY_ANALYZERstep in ingestion monitoring shows events passing through. See Monitor data ingestion.The
DOCUMENT_STOREcount is consistent with it. A gap between the two is the activities your analyzer dropped: check that it matches what your filtering is meant to discard.A stored activity carries
processed_by, the list of the activity analyzers that processed it, and$error_analyzer_id, an error ID, when an activity analyzer failed on it.A dropped activity is not stored at all: it appears on no timeline and carries neither field. Read your plugin logs to confirm it took the drop path.
A real activity shows the enrichment applied.
Identifiers are unchanged, as expected.
Related pages
Last updated
Was this helpful?