> For the complete documentation index, see [llms.txt](https://docs.mediarithmics.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mediarithmics.io/setup-and-monitor/collect-and-manage-your-data/import-data-in-batch/import-activities.md).

# 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.

{% hint style="danger" %}
Activities imported in bulk **do not go through the** [**activity processing pipeline**](/setup-and-monitor/collect-and-manage-your-data/collect-data-in-real-time.md#the-processing-pipeline) by default.

Consequences you must design around:

* Your [activity analyzers](/setup-and-monitor/collect-and-manage-your-data/collect-data-in-real-time/activity-analyzers.md) do **not** process these activities. **Format them exactly as you expect them to be stored.**
* Do not use this feature if you intend to rely on conversion detection or automation activation for these activities.
  {% endhint %}

If you do need the pipeline, set `use_processing_pipeline` to `true` on the document import - see [the document import object](/setup-and-monitor/collect-and-manage-your-data/import-data-in-batch.md#the-document-import-object).

## How to

{% stepper %}
{% step %}

### Create the document import

With document type `USER_ACTIVITY` and mime type `APPLICATION_X_NDJSON`. Only `ndjson` is supported for user activities.

```bash
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>"
}'
```

{% endstep %}

{% step %}

### Create an execution with your activities

Each line is one [UserActivity](/setup-and-monitor/collect-and-manage-your-data/collect-data-in-real-time.md#the-useractivity-object) object.

```bash
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":{}}]}'
```

{% endstep %}

{% step %}

### Check the execution result

Read `total_success`, `total_failure`, and the error file. See [reading the result](/setup-and-monitor/collect-and-manage-your-data/import-data-in-batch.md#reading-the-result).
{% endstep %}
{% endstepper %}

{% hint style="success" %}
You can upload many activities at once. The data is `ndjson`, not `json` - activities are separated by a line separator `\n`, **not** by commas.
{% endhint %}

## Formatting the activities

Because nothing transforms them on the way in, everything has to be right in the file:

| Decision          | Guidance                                                                                                                                                                                                                                                                                                                     |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `$type`           | `TOUCH` for offline activities that are not a site, app, or CTV visit. The full list is in [the activity types table](/setup-and-monitor/collect-and-manage-your-data/collect-data-in-real-time.md#activity-types).                                                                                                          |
| `$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](/setup-and-monitor/collect-and-manage-your-data/design-your-data-model-and-schema/standard-events.md) 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](/setup-and-monitor/collect-and-manage-your-data/collect-data-in-real-time.md#the-activity-unique-key). |
| Identifier        | **One identifier per line.** See [identifiers in imports](/setup-and-monitor/collect-and-manage-your-data/import-data-in-batch.md#identifiers-in-imports).                                                                                                                                                                   |

## Verify

* The execution reports the number of successes you expected.
* The `DOCUMENT_IMPORT` step appears in ingestion monitoring. See [Monitor data ingestion](/setup-and-monitor/operate-and-monitor/monitor-data-ingestion.md).
* 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

<table data-view="cards" data-search="false"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Import data in batch</strong></td><td>Document imports, executions, and results.</td><td><a href="/setup-and-monitor/collect-and-manage-your-data/import-data-in-batch.md">Import data in batch</a></td></tr><tr><td><strong>Collect data in real time</strong></td><td>The activity object you are formatting.</td><td><a href="/setup-and-monitor/collect-and-manage-your-data/collect-data-in-real-time.md">Collect data in real time</a></td></tr><tr><td><strong>Import profiles</strong></td><td>The other main import from your information systems.</td><td><a href="/setup-and-monitor/collect-and-manage-your-data/import-data-in-batch/import-profiles.md">Import profiles</a></td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.mediarithmics.io/setup-and-monitor/collect-and-manage-your-data/import-data-in-batch/import-activities.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
