> For the complete documentation index, see [llms.txt](https://fredhopper.gitbook.io/product-discovery/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fredhopper.gitbook.io/product-discovery/tracking-and-sending-events/activities/activity-object.md).

# Activity Object

Understand the activity object structure for event tracking: action, target, user, source ID, and metadata. Includes built-in actions and metadata recommendations for XO and FHR.

The activity object contains essential data for event tracking, comprising five unique properties, as shown below:

```json
{
    "action": "action",
    "target": {},
    "user": {},
    "sourceId": "source-id",
    "metadata": {}
}
```

## Action

The **action** property is a **string** describing the action performed by the user (i.e. the event the user has triggered).

Our system supports five built-in actions:

* [**View**](/product-discovery/tracking-and-sending-events/activities/view.md)
* [**Click**](/product-discovery/tracking-and-sending-events/activities/click.md)
* [**Add-to-cart**](/product-discovery/tracking-and-sending-events/activities/add-to-cart.md)
* [**Remove-from-cart**](/product-discovery/tracking-and-sending-events/activities/remove-from-cart.md)
* [**Purchas**](/product-discovery/tracking-and-sending-events/activities/purchase.md)<mark style="color:blue;">**e**</mark>

{% hint style="info" %}
If you would like to track additional actions, you can do so using [**custom actions**](/product-discovery/tracking-and-sending-events/activities/custom-actions.md).
{% endhint %}

## Target

The **target** property is an **object** detailing the target the action was performed on (i.e. the subject of the event).

Targets are **action specific** (e.g. product ID, path to page etc.).

## User

The **user** property is an **object** detailing the user characteristics you are tracking.

You can find more information on the **user** object in the [**Identities**](/product-discovery/tracking-and-sending-events/identities.md)[ section](/product-discovery/tracking-and-sending-events/identities.md).

## Source ID

The **source ID** links an activity to a specific context or origin. When a user takes an action, the **source ID** helps trace it back to a particular touchpoint, such as a page, a search term, or a specific marketing campaign.

The **source ID** property is a **string** describing the ID that associates the FHR or XO response with the event.

{% hint style="warning" %}
For activities linked to a FHR or XO context the source ID must correspond to the response ID.
{% endhint %}

For example: If a user clicks on a product recommendation, the **source ID** might link that action to the specific recommendation engine or search query that suggested the product.

<details>

<summary>Response object example: XO</summary>

Below you can find an example of an XO response object. The response ID, that you should use as source ID for tracking, corresponds to the `id` in the response object.

<pre data-overflow="wrap" data-line-numbers><code>{
  "id": "<a data-footnote-ref href="#user-content-fn-1">b252e3c0-d981-11ef-a83e-357cb5e776e3</a>",
  "recommendations": [
    {
      "id": "goomazon-oklexa",
      "strategy": "local-mostPopular",
      "score": 1,
      "distribution": 0,
      "product": {
        "_id": {
          "original_id": "goomazon-oklexa",
          "tenant": "615b225f20b888ce230ce617",
          "kind": "product"
        },
        "type": "product",
        "context": "default",
        "version": 0,
        "title": "Goomazon Oklexa SP93",
        "recommended": true,
        "scores": {
          "BestMatch": 1,
          "BestSeller": 0,
          "price_ascending": 0,
          "price_descending": 0
        },
        "metadata": {
          "updated": "1701820981438"
        },
        "photo": "https://zzfz-003.dx.commercecloud.salesforce.com/on/demandware.static/-/Sites-electronics-m-catalog/default/dw6891a144/images/large/SmartLiving/test_speaker_2.jpeg",
        "categories": [
          "SmartLiving"
        ],
        "brand": "SmartLiving",
        "classification-category": "tools",
        "short_description": "The Oklexa SP93 takes the concept of smart speakers to a whole new level! It will do exactly what you expect to do within its configured parameters. By analyzing the volume and pitch of your voice, Oklexa also takes into account visual data, (it's connected to all the cameras in your house), and can literally read your mind! Science!"
      }
    },
    {
      "id": "detector-brn5",
      "strategy": "local-mostPopular",
      "score": 1,
      "distribution": 0,
      "product": {
        "_id": {
          "original_id": "detector-brn5",
          "tenant": "615b225f20b888ce230ce617",
          "kind": "product"
        },
        "type": "product",
        "context": "default",
        "version": 0,
        "title": "Smoke detector BRN5",
        "recommended": true,
        "scores": {
          "BestMatch": 1,
          "BestSeller": 0,
          "price_ascending": 0,
          "price_descending": 0
        },
        "metadata": {
          "updated": "1701820981436"
        },
        "photo": "https://zzfz-003.dx.commercecloud.salesforce.com/on/demandware.static/-/Sites-electronics-m-catalog/default/dw6891a144/images/large/SmartLiving/BRN5.jpg",
        "categories": [
          "SmartLiving"
        ],
        "brand": "SmartLiving",
        "classification-category": "tools",
        "short_description": "The BRN5 is an intelligent smoke detector. The main purpose is of course to inform you via mobile devices when smoke production is detected. Built-in Alexa support also allows you to control other aspects of your smart home."
      }
    },
    {
      "id": "d1r7-tr4p",
      "strategy": "local-mostPopular",
      "score": 1,
      "distribution": 0,
      "product": {
        "_id": {
          "original_id": "d1r7-tr4p",
          "tenant": "615b225f20b888ce230ce617",
          "kind": "product"
        },
        "type": "product",
        "context": "default",
        "version": 0,
        "title": "Cleaning Robot D1R7-TR4P",
        "recommended": true,
        "scores": {
          "BestMatch": 1,
          "BestSeller": 0,
          "price_ascending": 0,
          "price_descending": 0
        },
        "metadata": {
          "updated": "1701820981472"
        },
        "photo": "https://zzfz-003.dx.commercecloud.salesforce.com/on/demandware.static/-/Sites-electronics-m-catalog/default/dw6891a144/images/large/SmartLiving/staubsauger-schwarz.jpg",
        "categories": [
          "SmartLiving"
        ],
        "brand": "SmartLiving",
        "classification-category": "tools",
        "short_description": "The D1R7-TR4P cleaning robot helps you keep your house clean. Due to its low overall height and flexible design, no place is neglected."
      }
    }
  ],
  "pagination": {
    "total": 3
  },
  "widget": {
    "title": "",
    "attributes": {

    },
    "minResults": -1,
    "distributions": [
      {
        "attributes": {

        }
      }
    ]
  }
}
</code></pre>

</details>

<details>

<summary>Response object example: FHR</summary>

You can find various examples for the FHR response object [here](/product-discovery/building-the-front-end-experience-with-fhr/understanding-the-fhr-query-response/fredhopper-query-and-response-samples.md). The response ID, that you should use as source ID for tracking, corresponds to the `rid` in the FHR response object.

</details>

**To ensure accurate reporting**, use the FHR or XO response ID **exclusively** for actions related to the features provided by that specific response.

{% hint style="warning" %}
Avoid including a source ID that is unrelated to the action.
{% endhint %}

### **Handling infinite scroll**

* **First response:** The initial set of results corresponds to the first response. Activities performed on these products should use the source ID from this response.
* **Subsequent responses:** When a user scrolls and additional content is loaded (e.g., a second page of results), the new products should reference the source ID from the corresponding response.

{% hint style="info" %}
Pagination events are not tracked. If you would like to track pagination events, request a [custom action](/product-discovery/tracking-and-sending-events/activities/custom-actions.md).
{% endhint %}

## Metadata

The **metadata** property is an **object** detailing additional data related to the action that you are tracking, for example:

* Locale (language and region)
* Device type (mobile, desktop)
* Quantity
* Price

**When using XO, we recommend you include the** `metadata.context` **field.** This is a **string** field describing the context that the event took place in. Values for this field are user defined and can take any format (e.g. "sale", "french", "1").

**When using FHR, we recommend you include the** `metadata.locale` **field.** This is a **string** field describing the locale that the event took place in. Values for this field must adhere to the following format: xx\_YY (e.g. "en\_GB", "en\_US", "fr\_FR").

Additional fields in the `metadata` object are **action specific** and may be **required**.

## FHR Response Mapping

To successfully track events, certain fields in the activity object must be populated with values returned directly from the FHR query response. This section outlines the fields whose values are sourced exclusively from those responses. Any other values are derived from customer input.

| JSON Field          | Detailed Source Information                                                                                                                                                                                                                                                                                                                                                                                    |
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sourceId`          | see [Source ID](#source-id)                                                                                                                                                                                                                                                                                                                                                                                    |
| `target.product`    | <p><code>universes.universe.items-section.items.item\[i].attributes\[where .name == "secondid"].value.value</code><br><img src="https://3916646904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfLO8j00CcKdYax4GPUyE%2Fuploads%2FUDTXnhGzyNOKVrlmfEGv%2Fsecondid_JSON.png?alt=media&amp;token=1a7e1174-871f-4c67-9b8f-a6561a8bc963" alt=""></p>                                         |
| `target.facet`      | <p><code>universes.universe.facetmap.filter\[where .seleceted == "true"].facetid</code><br><img src="https://3916646904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfLO8j00CcKdYax4GPUyE%2Fuploads%2FWgsyYdFyEqCkkD45rRYa%2Ffacetid.png?alt=media&amp;token=728efe05-a82e-487c-98c0-3d97a91c5cb1" alt=""></p>                                                                          |
| `target.[facet-id]` | <p><code>universes.universe.facetmap.filter\[where .seleceted == "true"].filterselection\[where .seleceted == "true"].value.value</code><br><img src="https://3916646904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfLO8j00CcKdYax4GPUyE%2Fuploads%2F2zFG4nWqBKqmHulMXF13%2Ffacetvalue.png?alt=media&amp;token=c8458e39-770d-467c-9746-8388ec589e0f" alt="" data-size="original"></p> |
| `target.campaign`   | <p><code>themes\[i].theme\[where .items is not empty].id</code><br><img src="https://3916646904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfLO8j00CcKdYax4GPUyE%2Fuploads%2FrHJWPPRhuk7U12rJKFYn%2Ftheme.png?alt=media&amp;token=824fb17e-3486-47bb-81d7-57b51aa9487d" alt=""></p>                                                                                                    |
| `metadata.query`    | <p><code>searchterms.term.value</code><br><img src="https://3916646904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfLO8j00CcKdYax4GPUyE%2Fuploads%2FMpRuzV76rmWJmDXkpkzB%2Fimage.png?alt=media&amp;token=9970b494-314d-4fdf-883d-c8b76ce435bb" alt=""></p>                                                                                                                             |

[^1]: response ID
