For the complete documentation index, see llms.txt. This page is also available as Markdown.

Build an activity analyzer

Write and deploy the plugin that transforms each activity before it is stored.

Your goal

Implement an activity analyzer plugin: one endpoint that receives an activity and returns the activity you want stored, or asks the platform to discard it.

Expected outcome

A deployed plugin version your users can attach to a channel, reformatting or enriching every real-time activity on it.

Before you start

  • Read Activity analyzers for what an analyzer does, where it sits in the pipeline, and what it may and may not change.

  • Read Plugin architecture for the plugin, version, worker, and instance model.

  • Check whether an event rule already covers your case - a rule needs no code.

Create the plugin with type ACTIVITY_ANALYZER, following the procedure in Build a custom feed plugin.

The standard group ID for an activity analyzer is {domain}.{organisation}.activity-analyzer - for example com.mediarithmics.activity-analyzer.

The one endpoint to implement

POST myworker/v1/activity_analysis

Called any time an activity is processed by the platform. The analyzer receives an activity and responds with a new activity, or asks the platform to discard it.

Request field
Type
Description

activity_analyzer_id

String

The ID of the analyzer instance to use. Used to retrieve the instance properties.

datamart_id

String

The ID of the datamart.

activity

Object

The UserActivity object to analyse.

In most cases, respond with the modified activity object to store:

To have the platform discard the activity instead of storing it:

On an unexpected error:

Drop an activity

To discard a whole activity - unwanted traffic such as browser bots, for instance - respond { "status": "drop" } with an HTTP 200. With the Plugin SDK, return the response built by core.dropActivity():

The status is matched exactly, in lowercase. Any other value, DROP included, is handled as an error response.

A drop is a successful response, not an error. What it changes for the activity and for the analyzers after yours on the channel, and why your filtering must run before any forwarding to a third party, is in Dropping an activity.

Read your instance

The same version is attached to several channels, and each attachment is a separate instance with its own properties. Use activity_analyzer_id from the request to fetch them:

The first returns the instance - name, organisation, plugin ID, group ID, artifact ID. The second returns its properties, each with a technical name, value, type, origin, and whether it is writable.

Cache the properties rather than fetching them per activity: this endpoint is called for every activity on the channel.

Design guidance

Concern
Guidance

Latency

The analyzer sits in the ingestion path. An external lookup per activity puts that provider's latency between your users and their stored data - cache aggressively.

External calls

Any host you call must be declared as an external service and enabled by mediarithmics. See Build a custom feed plugin.

Rate limits

If you call a partner API, configure a throttling on the version.

Bulk imports

Analyzers do not run on bulk activity imports. If a transformation is mandatory for correctness, imported activities must already be formatted correctly. See Import activities.

Edge

Properties that must be usable in Edge segment queries must be stored exactly as pushed - they cannot pass through your analyzer. See Edge.

Watch it in production

Everything written through the Plugin SDK's Logger class is available as logs, in a stream dedicated to the plugin's organisation.

1

Get access

Ask your Account Manager for access to your organisation's plugin logs if you do not already have it. Streams are named {Organisation ID} {Organisation name}.

2

Add context to every log line

Systematically include context - feed ID, site ID, app ID - so you can filter down to a specific instance of your plugin. Without it, logs from every instance are interleaved.

3

Use the right level

Levels are Error, Log, Info, and Debug.

Use Debug for log-intensive work such as tracing data and functions. Debug logs are not saved by default, and your Account Manager can enable them temporarily - which lets you leave tracing in the code without generating useless volume.

4

Keep the volume down

A good practice: generate statistics every few seconds rather than a line per item - the number of items processed and their status, instead of a message per activity.

Alongside logs, watch the ACTIVITY_ANALYZER and DOCUMENT_STORE steps in ingestion monitoring: a gap between them is the activities your analyzer dropped.

Verify

  • A test activity returns transformed as expected, with identifiers untouched.

  • Two instances on two channels behave according to their own properties.

  • The ACTIVITY_ANALYZER and DOCUMENT_STORE counts are consistent, once the activities you drop on purpose are accounted for.

  • A test activity you mean to discard returns { "status": "drop" } and appears on no timeline.

  • Logs can be filtered down to one instance.

  • An error in your code returns the error shape rather than timing out.

Last updated

Was this helpful?