Import activities
Insert activities that happened outside real-time tracking, such as store visits and offline purchases.
Your goal
Get activities that never passed through a tag or an API call into the datamart - offline purchases, store visits, call-centre interactions - so they sit on the same user timeline as online behaviour.
Expected outcome
Activities stored exactly as you formatted them, attached to the right UserPoints.
If you do need the pipeline, set use_processing_pipeline to true on the document import - see the document import object.
Run an activity import
Create the document import
With document type USER_ACTIVITY and mime type APPLICATION_X_NDJSON. Only ndjson is supported for user activities.
curl -X POST \
https://api.mediarithmics.com/v1/datamarts/<DATAMART_ID>/document_imports \
-H 'Authorization: <YOUR_API_TOKEN>' \
-H 'Content-Type: application/json' \
-d '{
"document_type": "USER_ACTIVITY",
"mime_type": "APPLICATION_X_NDJSON",
"encoding": "utf-8",
"name": "<YOUR_DOCUMENT_IMPORT_NAME>"
}'Create an execution with your activities
Each line is one UserActivity object.
curl -X POST \
https://api.mediarithmics.com/v1/datamarts/<DATAMART_ID>/document_imports/<DOCUMENT_IMPORT_ID>/executions \
-H 'Authorization: <API_TOKEN>' \
-H 'Content-Type: application/x-ndjson' \
-d '{ "$user_agent_id": "<USER_AGENT_ID>", "$type":"TOUCH", "$session_status":"NO_SESSION", "$ts":<TIMESTAMP>, "$events":[{"$event_name":"<EVENT_NAME>","$ts":<TIMESTAMP>,"$properties":{}}]}'Check the execution result
Read total_success, total_failure, and the error file. See reading the result.
Formatting the activities
Because nothing transforms them on the way in, everything has to be right in the file:
$type
TOUCH for offline activities that are not a site, app, or CTV visit. The full list is in the activity types table.
$session_status
NO_SESSION for imported offline activities - there is no session to aggregate.
$ts
The timestamp of the activity, in milliseconds.
Event names
Use predefined names so analytics counts them.
Properties
Must match the paths your schema expects, since no event rule or analyzer will move them.
$unique_key
Set it deliberately if you may re-import the same data. Datamart ID, UserPoint ID, timestamp, and unique key together identify an activity - identical values replace the previous one. See the activity unique key.
Identifier
One identifier per line. See identifiers in imports.
Verify
The execution reports the number of successes you expected.
The
DOCUMENT_IMPORTstep appears in ingestion monitoring. See Monitor data ingestion.A known user's timeline shows the imported activity, with properties in the right place.
Re-running the same file does not duplicate activities, if you set unique keys.
Related pages
Last updated
Was this helpful?