> 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/collect-data-in-real-time/activities-analytics.md).

# Activities analytics

How the platform duplicates activities for performance analytics, and how to make custom events count.

## Your goal

Understand what the platform builds from your activities so that session duration, conversions, and funnels are populated - and get your custom events counted when renaming your tracking is not an option.

## Expected outcome

Built-in dashboards and funnel analytics showing your real volumes, not zeros.

## Why a separate store exists

Data entering your datamart is stored in a multi-model database, optimised for different usages. To display performance analytics - session duration, conversions, funnels - **the platform duplicates some user activities and information and optimises them**.

That duplication is what analytics reads. And it only happens for **predefined** events.

{% hint style="warning" %}
Custom events are **not taken into account** when calculating metrics. Do not create an `order` event when tracking an e-commerce site - use the predefined `$transaction_confirmed`. Conversions and amounts are calculated from `$transaction_confirmed` events, not from `order` events.
{% endhint %}

A sample event that analytics can use:

```json
{
    "$ts": 3489009384393,
    "$event_name": "$transaction_confirmed",
    "$properties": {
        "$items": [
            {
                 "$id": "product_ID",
                 "$qty": 20,
                 "$price": 102.8,
                 "$brand": "Apple",
                 "$category1": "Category 1",
                 "$category2": "Category 2",
                 "$category3": "Category 3",
                 "$category4": "Category 4"
            }
        ],
        "$currency": "EUR"
    }
}
```

Which events feed which analytics, and which properties matter, is tabulated in [Standard events](/setup-and-monitor/collect-and-manage-your-data/design-your-data-model-and-schema/standard-events.md#which-events-feed-which-analytics).

## Retention

{% hint style="info" %}
Activities analytics data is kept **4 months**, in order to optimise performance.
{% endhint %}

This is not configurable. If you need a longer analytical history, extract it - see [Export your data](/setup-and-monitor/collect-and-manage-your-data/export-your-data.md) and [Data retention](/setup-and-monitor/plan-and-integrate/set-up-the-environment/manage-data-retention.md).

## Transforming your custom events

If you already send custom events and cannot change your tracking, you can declare an **event transformation** so analytics still works.

{% hint style="warning" %}
Two limits to be clear about:

* **Only events entering the datamart after the transformation is defined are transformed.** Existing data is not reprocessed.
* **Transformations do not change your activities and events anywhere else** - they exist for analytics. To transform events everywhere, use an [activity analyzer](/setup-and-monitor/collect-and-manage-your-data/collect-data-in-real-time/activity-analyzers.md).
  {% endhint %}

### The transformation

A transformation is linked to a datamart:

```json
{
    "channel_id": "8888",
    "source_event_name": "order",
    "target_event_name": "$transaction_confirmed",
    "mapping_id": 15
}
```

| Property            | Type    | Description                                                                                                                 |
| ------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------- |
| `datamart_id`       | Integer | The datamart where the transformation applies.                                                                              |
| `channel_id`        | Integer | The channel where it applies.                                                                                               |
| `source_event_name` | String  | The name of your custom event.                                                                                              |
| `target_event_name` | String  | The predefined event it becomes. Allowed values: `$transaction_confirmed`, `$item_view`, `$basket_view`, `$list_item_view`. |
| `mapping_id`        | Integer | The property mapping to apply.                                                                                              |

Manage them with:

```
GET  https://api.mediarithmics.com/v1/datamarts/:datamartId/analytics_event_transformation
POST https://api.mediarithmics.com/v1/datamarts/:datamartId/analytics_event_transformation
```

### The property mapping

A mapping decides which property of your custom event becomes which property of the predefined event. Each entry pairs a `target_attribute_name` with a `source_attribute_path`, and paths can be nested through `sub_path`.

<details>

<summary>A mapping for <code>$transaction_confirmed</code></summary>

This maps `$properties.order.order_products[]` onto `$items[]`, and each product's fields onto the `$items` fields analytics expects:

```json
{
  "mapping": {
    "values": [
      {
        "target_attribute_name": "$items",
        "source_attribute_path": {
          "attribute_name": "$properties",
          "sub_path": {
            "attribute_name": "order",
            "sub_path": { "attribute_name": "order_products" }
          }
        },
        "children": [
          {
            "target_attribute_name": "$id",
            "source_attribute_path": {
              "attribute_name": "product",
              "sub_path": { "attribute_name": "id" }
            }
          },
          { "target_attribute_name": "$qty",   "source_attribute_path": { "attribute_name": "qty" } },
          { "target_attribute_name": "$price", "source_attribute_path": { "attribute_name": "price" } },
          { "target_attribute_name": "$ean",   "source_attribute_path": { "attribute_name": "ean" } },
          { "target_attribute_name": "$brand", "source_attribute_path": { "attribute_name": "brand" } },
          { "target_attribute_name": "$category1", "source_attribute_path": { "attribute_name": "cat1" } },
          {
            "target_attribute_name": "$category2",
            "source_attribute_path": { "absolute_path": true, "attribute_name": "$event_name" }
          },
          { "target_attribute_name": "$category3", "source_attribute_path": { "attribute_name": "cat3" } },
          { "target_attribute_name": "$category4", "source_attribute_path": { "attribute_name": "cat4" } }
        ]
      }
    ]
  }
}
```

Three things to note:

* **The target attributes are fixed.** You cannot use target attributes other than the ones above, but they are not all mandatory - an unused target uses its default value.
* **`absolute_path: true`** reads from the root of the event rather than from the mapped item. In the example, `$category2` takes `event.$event_name` instead of a field inside each product.
* If the event has no repeated element, you can map `$properties` directly onto `$items` - it is then treated as an array of one item.

</details>

{% hint style="warning" %}
Map the event JSON **as it is stored in the database** and visible in user timelines - that is, *after* activity analyzers have run, not as your website sends it.
{% endhint %}

## Verify

* Built-in dashboards show non-zero conversions and amounts.
* Funnel analytics can filter by product ID, brand, and category.
* After declaring a transformation, new events appear in analytics - and you have not expected old ones to.

## 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>Standard events</strong></td><td>The events and properties analytics reads.</td><td><a href="/setup-and-monitor/collect-and-manage-your-data/design-your-data-model-and-schema/standard-events.md">Standard events</a></td></tr><tr><td><strong>Data cube (Activities Analytics)</strong></td><td>Querying this store yourself.</td><td><a href="/setup-and-monitor/operate-and-monitor/query-your-datamart/data-cube-activities-analytics.md">Data cube (Activities Analytics)</a></td></tr><tr><td><strong>Activity analyzers</strong></td><td>Transforming events everywhere, not just for analytics.</td><td><a href="/setup-and-monitor/collect-and-manage-your-data/collect-data-in-real-time/activity-analyzers.md">Activity analyzers</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/collect-data-in-real-time/activities-analytics.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.
