Skip to content

Commit

Permalink
Merge pull request #383 from deco-sites/docs/ab-test-g4a-setup
Browse files Browse the repository at this point in the history
Adding the topic Setting up GA4 for A/B testing to the How do I create and track an A/B test? section
  • Loading branch information
lucassa-bit authored Oct 2, 2024
2 parents d952931 + 84511b2 commit d9ccf74
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
34 changes: 34 additions & 0 deletions docs/developing-capabilities/apps/ab-test/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Let's explore each step:
- Editing your variant
- Creating events and collecting data
- Funnel and results
- GA4 Setup for A/B Testing

## Creating an Experiment

Expand Down Expand Up @@ -118,3 +119,36 @@ Data is transferred in real-time, no more waiting a day or two to analyze them.
![Experiments screen](https://ozksgdmyrqcxcwhnbepg.supabase.co/storage/v1/object/public/assets/530/6ddc740d-9590-431b-b1e7-f0a0130bc5f6)

![Experiments screen](https://ozksgdmyrqcxcwhnbepg.supabase.co/storage/v1/object/public/assets/530/cc637298-e938-494c-9253-b7d1bef6f99a)

## GA4 Setup for A/B Testing

To ensure data consistency while navigating an A/B test on deco.cx, we use a cookie called deco_segment.

This cookie lasts for 30 days by default and can be used to determine which version the user is in.

All data sent to the deco.cx Analytics is already segmented by version.

However, for this to also occur in GA4, it is necessary to check this cookie and segment the events based on that information.

- Example of cookie:
```
deco_segment=TdCJTIyYWN0aXZlJTIyJTNBJTVCJTVEJTJDJTIyaW5hY3RpdmVEcmF3biUyMiUzQSU1QiUyMlRlc3RlJTIwVGF2YW5vJTIyJTVEJTdE
```

- To extract readable data from this hash, use the following function:
```javascript
getData(myCookie) {
return JSON.parse(decodeURIComponent(atob(myCookie)))
}

```

- This will return an object like:
```json
{
active: [],
inactiveDrawn: ['Teste Tavano']
}
```

This way, in GTM, you can identify whether the user is participating in Test X, allowing for the segmented and accurate dispatch of events.
32 changes: 32 additions & 0 deletions docs/developing-capabilities/apps/ab-test/pt.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,35 @@ analisá-los.
![Experiments screen](https://ozksgdmyrqcxcwhnbepg.supabase.co/storage/v1/object/public/assets/530/6ddc740d-9590-431b-b1e7-f0a0130bc5f6)

![Experiments screen](https://ozksgdmyrqcxcwhnbepg.supabase.co/storage/v1/object/public/assets/530/cc637298-e938-494c-9253-b7d1bef6f99a)

## Setup do GA4 para Teste A/B

Para assegurar a consistência dos dados fornecidos fornecidos ao navegar em um Teste A/B na deco.cx, utilizamos um cookie, chamado _deco_segment_.

Esse cookie dura por padrão 30 dias e pode ser utilizado para entender em qual versão o usuário está.

Todos os dados que vão para o Analytics da deco.cx, já são separados por segmento.

Porém, para que isso também aconteça no GA4, é necessário verificar esse cookie e segmentar os eventos com base nessa informação.

- Exemplo de cookie
```
deco_segment=TdCJTIyYWN0aXZlJTIyJTNBJTVCJTVEJTJDJTIyaW5hY3RpdmVEcmF3biUyMiUzQSU1QiUyMlRlc3RlJTIwVGF2YW5vJTIyJTVEJTdE
```

- Para extrair o dado legível deste hash, utilize a função:
```javascript
getData(myCookie) {
return JSON.parse(decodeURIComponent(atob(myCookie)))
}
```

- Isso irá devolver um objeto como:
```json
{
active: [],
inactiveDrawn: ['Teste Tavano']
}
```

Dessa forma, no GTM, você consegue identificar se o usuário está participando do Teste X, permitindo o envio de eventos de forma segmentada e precisa.

0 comments on commit d9ccf74

Please sign in to comment.