Activity analyzers
Last updated
Was this helpful?
Last updated
Was this helpful?
An Activity Analyzer is a that allows you to modify an activity on the fly before storing it. It runs as a part of , 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
Activity analyzers have only one predefined endpoint to implement
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.
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
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.
id
string
ID of the activity analyzer, typically the activity_analyzer_id
from the incoming request.
GET
https://api.mediarithmics.com/v1/activity_analyzers/:id/properties
Get the properties associated with the activity analyzer instance
id
string
ID of the activity analyzer, typically theactivity_analyzer_id
from the incoming request
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
.
We can provide you with a hello world project using our SDK. Please contact your Account manager in order to have access to it.
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
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
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...
Make sure to define the right order and error recovery strategies.
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.
See to learn why you should use the activity_analyzer_id
parameter to retrieve the instance properties.
The code of the activity analyzer can call the following API endpoints to retrieve.
See the plugins documentation to see .
Use our 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 .
The project structure and files work as .
As activity analyzers are plugin, you can monitor them.
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 to understand when you should see your activity or how you could fasten the process.