> For the complete documentation index, see [llms.txt](https://docs.adpage.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.adpage.io/documentation/documentation-nl/integraties-websites/aangepast/datalayer-gebeurtenissen-toevoegen.md).

# dataLayer-gebeurtenissen toevoegen

Leer hoe je aangepaste dataLayer-gebeurtenissen instelt

### 1. bouw de dataLayer-gebeurtenissen

AdPage volgt de dataLayer-standaard van Google Tag Manager. Lees meer over de gebeurtenisstructuur in de [Google-documentatie](https://support.google.com/analytics/answer/9267735?hl=en).

De volgende gebeurtenissen zijn belangrijk voor een eCommerce-website:

* user\_data (geïnstalleerd in stap 2.1)
* view\_item\_list ([Google-documentatie](https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#view_item_list))
* view\_item ([Google-documentatie](https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#view_item))
* add\_to\_cart ([Google-documentatie](https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#add_to_cart))
* remove\_from\_cart ([Google-documentatie](https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#remove_from_cart))
* view\_cart ([Google-documentatie](https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#view_cart))
* begin\_checkout ([Google-documentatie](https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#begin_checkout))
* add\_payment\_info ([Google-documentatie](https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#add_payment_info))
* add\_shipping\_info ([Google-documentatie](https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#add_shipping_info))
* purchase ([Google-documentatie](https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#purchase))

> **Opmerking:** Deze gebeurtenissen zijn een leidraad voor eCommerce-websites. Aangepaste gebeurtenissen of andere website-doelen, zoals leadgeneratie, kunnen andere gebeurtenissen vereisen.

Voorzie gebeurtenissen van het voorvoegsel `trytagging_` om conflicten met bestaande dataLayer-gebeurtenissen te voorkomen.

### 2. Voeg de user\_data dataLayer-gebeurtenis toe

De `user_data` gebeurtenis is de eerste gebeurtenis die op je website wordt verzonden. Voeg deze toe vóór andere dataLayer-gebeurtenissen. Hij fungeert als het startsignaal van Google Tag Manager. Trackinggegevens komen mogelijk niet correct aan zonder deze.

{% hint style="info" %}
Bij gebruik van webhooks moet elke pagina overschrijven `client_id`, `session_id`, en `session_count` met door Google gegenereerde ID's. Activeer de Google-tag vanuit de dataLayer `user_data` gebeurtenis. Activeer elke andere gebeurtenis pas na de Google-tag.
{% endhint %}

De `user_data` gebeurtenis vereist een extra script. Voeg dit script toe aan de `<body>`:

```xml
<script  defer  src="https://[connected_domain_name]/user-data-minified.js">
</script>
```

{% hint style="info" %}
**Opmerking:** Vind het gekoppelde domein in de installatielink. Je vindt het ook onder **Implementatie** → **Domeinnaam** in het AdPage Tagging-dashboard. Werk de URL voor elk domein bij.
{% endhint %}

Dit script biedt twee JavaScript-hulpfuncties:

```javascript
window.taggingHelpers.getMarketingObject(); // Marketingobject

window.taggingHelpers.getDeviceInfo(); // Apparaatobject
```

Verzend vervolgens de eerste `user_data` gebeurtenis in JavaScript:

```javascript
// Voer deze code pas uit nadat window.taggingHelpers beschikbaar is.
// Het wordt geladen via een defer-tag, dus het blokkeert de website niet.

window.dataLayer.push({

  event: "trytagging_user_data",

  marketing: window.taggingHelpers.getMarketingObject(),

  device: window.taggingHelpers.getDeviceInfo(),

});
```

Voeg `marketing` toe aan elke volgende gebeurtenis. Dit is een voorbeeld `view_item` gebeurtenis:

```php
window.dataLayer.push({

  event: "trytagging_view_item",

  ecommerce: {

    currency: "EUR",

    value: 100,

    items: [

      {

        item_id: "123456",

        item_name: "Product Name",

        price: 100,

        item_category: "Product Category",

      },

    ],

  },

  marketing: window.taggingHelpers.getMarketingObject(),

});
```

#### 2.1 Optioneel wachten op het user\_data-script

We raden aan om het `user_data` script met `defer`te laden. Hiermee krijgen andere kritieke pagina-elementen voorrang. Het betekent ook dat het script mogelijk niet direct beschikbaar is.

De `user_data` script verzendt een aangepaste JavaScript-gebeurtenis wanneer de functionaliteit beschikbaar komt. Gebruik die gebeurtenis als volgt:

```javascript
document.addEventListener("trytagging_user_data_ready", (event) => {
  const marketingData = window.taggingHelpers.getMarketingObject();

  console.log("Marketinggegevens:", marketingData);
});
```


---

# 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.adpage.io/documentation/documentation-nl/integraties-websites/aangepast/datalayer-gebeurtenissen-toevoegen.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.
