Activity analyzers
An Activity Analyzer is a Plugin that allows you to modify an activity on the fly before storing it. It runs as a part of the processing pipeline, for each activity of the channel it is associated with.
This feature is useful for:
Reformatting data (adapting the ingestion data model to the datamart schema)
Enriching events (for instance by fetching product information based on a product id)
Improving data quality (filtering unwanted events, matching input values to standard catalogs, parsing URLs into categories etc.)
If you don't know what a plugin is, you can find the complete documentation in the specific section.
An activity analyzer is only executed for activities tracked in real time, e.g. via the user_activity API, javascript tag or pixel tracking (see real time user tracking guide). If you want to upload bulk activities, make sure they are already formatted before starting the upload as the activity analyzer won't run.
The standard group ID for an activity analyzer is {domain}.{organisation}.activity-analyzer, for example com.mediarithmics.activity-analyzer
Endpoints to implement
Activity analyzers have only one predefined endpoint to implement
Process an activity
POST
myworker/v1/activity_analysis
This entry point is called any time an activity is processed by the platform. The activity analyzer receives an activity and responds to the request by returning a new activity. It cannot modify the identifiers that are passed in the incoming activities.
Request Body
activity_analyzer_id
string
The ID of the activity analyzer instance that should be used to process the activity. Used to retrieve the instance properties.
datamart_id
string
The ID of the datamart
activity
object
The User Activity Object to analyze
See Plugin Instances to learn why you should use the activity_analyzer_id
parameter to retrieve the instance properties.
Available outbound services
The code of the activity analyzer can call the following API endpoints to retrieve its instance context.
Retrieve the instance
GET
https://api.mediarithmics.com/v1/activity_analyzers/:id
Use the activity_analyzer_id from the incoming request to retrieve the activity analyzer instance that has been called.
Path Parameters
id
string
ID of the activity analyzer, typically the activity_analyzer_id
from the incoming request.
Retrieve the instance properties
GET
https://api.mediarithmics.com/v1/activity_analyzers/:id/properties
Get the properties associated with the activity analyzer instance
Path Parameters
id
string
ID of the activity analyzer, typically theactivity_analyzer_id
from the incoming request
Creating an activity analyzer
See the plugins documentation to see how plugins are created and deployed.
An activity analyzer has the ACTIVITY_ANALYZER
plugin type. Its group id should be {domain.organisation.activity-analyzer}
(for example com.mediarithmics.activity-analyzer). Its artifact id should be the name of the activity analyzer, ie update-product-infos
.
Use our Plugins SDK to create your activity analyzer in nodejs
: the required routes are already defined and you only have to override specific functions.
You can find a sample activity analyzer in the examples folder of the plugins SDK.
We can provide you with a hello world project using our SDK. Please contact your Account manager in order to have access to it.
The project structure and files work as with every other plugin.
Interfaces to implement
Your should extend ActivityAnalyzerPlugin
class and implement the instanceContextBuilder
and onActivityAnalysis
functions from the plugins SDK.
onActivityAnalysis
function is called every time an activity runs through the activity analyzer. It is responsible for the activity transformation.
The instance context built in instanceContextBuilder
is cached to improve performances. It should retrieve and store the plugin properties and configuration files used by the code.
Don't forget to catch your errors. You should log / respond with the appropriate message to facilitate debugging.
Your instance context interface should extend ActivityAnalyzerBaseInstanceContext
Creating an instance
Like other plugins, activity analyzer need to be instantiated. To create an instance, connect to Navigator and head toward Settings > Datamart > Activity Analyzers. You will get a list of existing instances and a button to create new ones.
Click on New Activity Analyzer.
Select the activity analyzer you want to instantiate.
Enter a name to easily recognize the instance, select an Error recovery strategy and fill Properties if you need to overwrite some of them. Save your modifications to create a new instance of your activity analyzer.
The error recovery strategy determines how the activity is processed when the plugin fails.
STORE_WITH_ERROR_ID
The activity will be sent without any modification to the next activity analyzer.
STORE_WITH_ERROR_ID_AND_SKIP_UPCOMING_ANALYZERS
The activity will be saved without modification of the activity analyzer in failure. It doesn't be sent to the next plugin.
DROP
The activity won’t be saved
Linking an instance to a channel
Once your activity analyzer instance is created, you can link it to one or multiple channels. To do so, connect to Navigator and head toward Settings > Datamart > Channels and select the channel where you want your activity analyzer to be executed.
Go to the Activity Analyzers category.
Click on Add an Activity Analyzer and select your instance.
Several activity analyzers can be used on the same channel. In this case, they will process the same activity in a sequence of your choice: the second analyzer will process the activity as rendered by the first one and so on...
Currently, you can't get more than 5 activity analyzers. If you need more, please contact your Account manager.
Make sure to define the right order and error recovery strategies.
Debugging
Plugin logs and metrics
As activity analyzers are plugin, you can monitor them as you do with all plugins.
Verifying an activity
User activities that run through activity analyzers are generally aggregated into sessions. You won't see your user activity until it has been put into a session and gone through the whole activity processing pipeline. See how sessions are built to understand when you should see your activity or how you could fasten the process.
Go to the navigator > monitoring and search for the user point associated with the activity.
Click on the view json button on any activity on a timeline
You can check if all the properties are OK and if your activity analyzers processed the activity as expect
In case of problem, you can look at two properties added to the activity. processed_by
will tell you if the activity has been processed by your activity analyzer, and $error_analyzer_id
will give you an error ID if the activity analyzer returned an error response.
Last updated