# Legacy Implementation through GTM

{% hint style="warning" %}

#### Legal Notice <a href="#legal-notice" id="legal-notice"></a>

*The following tracking script sets cookies into the users device. It tracks data which may be used for marketing optimization, content optimization or user segmentation. In some legislations the user needs to make an explicit consent before this code can be legally executed on his or her device.*

*As we only act as a data processor, you are responsible for obtaining consent in accordance with applicable legislation. If our tracking script gets activated and you have not complied with the applicable rules in obtaining user consent, you may be at risk of sanctions for which we are not responsible.*
{% endhint %}

If you are using Google Tag Manager on your website, this is the fastest way to implement Roivenue Measurement.

Your implementation will differ depending on the system you use for consent collection. If you use the default mechanism in Google Tag Manager for consent management, follow the steps [here](#implementation-for-default-gtm-consent-management-system). If you are using a custom consent management system, click [here](#implementation-for-custom-consent-management-solution).

## Implementation for default GTM Consent Management System

### Prerequisites <a href="#prerequisites" id="prerequisites"></a>

* **Property ID -** You will need this to set up your script correctly. Contact your account manager to obtain it.

### Initial Setup

1. Download the GTM container [here](https://roipublic.blob.core.windows.net/tagmanager/GTM-RM-built-in-consent.json).
2. Go to your GTM (at <https://tagmanager.google.com/> )
3. Go to Admin tab select “Import container”, select the container file you have downloaded. Select the workspace you want to import to and set “merge” option - as on the picture bellow.

<figure><img src="https://4279879158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MGvvrlVUvq4TNL0oYP6%2Fuploads%2FaTY9Gv1AE9Q8CE8PLxbD%2Fimage.png?alt=media&#x26;token=a4f32b27-cd9b-4847-9281-a1414b001619" alt=""><figcaption><p>Always set the import to Merge!</p></figcaption></figure>

4. Go to section “Variables”
5. Click on `roivenue.tracking.config` and change the values in the JSON object:
   1. `property_id` - Insert a Property Id provided by your account manager
   2. `api_url` - Check that "<https://tr.roivenue.com>” is filled in.
   3. `currency_code` - the default currency code that will be used for tracking purchases used in case that the currency is not specified in purchase object
   4. `event_types` - leave this blank unless otherwise agreed with your Account Manager.

<figure><img src="https://4279879158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MGvvrlVUvq4TNL0oYP6%2Fuploads%2F7SHu5evZh9qjOeYMm6ni%2Fimage.png?alt=media&#x26;token=216a7a0c-9532-4406-b2cd-f437f4580862" alt=""><figcaption><p>Fill in all the needed information</p></figcaption></figure>

### Setting up Triggers

{% hint style="info" %}
In this step, you are setting up when Roivenue Measurement script should run. By default it runs **with every page view.**
{% endhint %}

6. Navigate to Tags section.
7. Select `roivenue.tracking` code.
8. Go to the section “Triggering” and add all triggers when you want Roivenue Measurement script to run
9. that fire on all your conversion types and all events indicating a change in consent.

{% hint style="success" %}
The expected additional triggers are those which fire on all of your **conversion events** and also a trigger indicating a **change in consent** from a visitor. (By including this, you can switch between cookie and anonymous tracking within one session, if the consent is collected after the start of that session.)
{% endhint %}

<figure><img src="https://4279879158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MGvvrlVUvq4TNL0oYP6%2Fuploads%2Fpj9IgQAgUfzc5a1kPoFV%2Fimage.png?alt=media&#x26;token=0c45fc36-1896-482c-b4e4-68dd6516b3c0" alt=""><figcaption><p>Add all necessary triggers</p></figcaption></figure>

### Setting up Consents and Anonymous Tracking

{% hint style="info" %}
Roivenue Anonymous Tracking can be used to track users without using any cookies and to tracks users in a limited scope.
{% endhint %}

<figure><img src="https://4279879158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MGvvrlVUvq4TNL0oYP6%2Fuploads%2FEBPJ9ZhuJeoe4ww9zF4B%2Fimage.png?alt=media&#x26;token=bd0dae41-d01f-4a15-b4b9-ecd6e59230e9" alt=""><figcaption></figcaption></figure>

10. Continue the configuration of `roivenue.tracking` tag in the tag section.
11. Change consent settings to “Not set“.

<figure><img src="https://4279879158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MGvvrlVUvq4TNL0oYP6%2Fuploads%2F11AogvWhJQQRv2qgOohR%2Fimage.png?alt=media&#x26;token=58ba69cd-d49e-4255-b2b5-6fb65e3a9ff1" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
The default settings requires `analytics_storage` permission to be given and tracks users only if this permission was given. If you change it to "Not set", Roivenue Measurement will measure in the following way:&#x20;

* when `analytics_storage` is granted, cookies are used for tracking the user.
* when `analytics_storage` is not granted, all user data is stored in `sessionStorage` of the browser. It means that cookieless tracking is enabled.
  {% endhint %}

{% hint style="warning" %}
As we only act as a data processor, you are responsible for setting up the Roivenue Measurement in line with applicable legislation in your country.
{% endhint %}

### Setting up Conversions Tracking

{% hint style="info" %}

If you already have `ecommerce.purchase` event in `dataLayer`, you do not need to implement anything because we will use the following fields to track a **purchase** conversion.

* `value` - the conversion value
* `tax` - the tax
* `currency` - three letter ISO-4217 code of currency
* `transaction_id` - the transaction ID

And we save them into these variables in Roivenue:

* `conversionType`: 'purchase'
* `conversionId`: transaction\_id
* `conversionValue`: value - tax
* `currencyCode`: currency

This is how the event in your `dataLayer` should look like.

{% code lineNumbers="true" %}

```
window.dataLayer.push({
	event: 'purchase',
	ecommerce: {
		transaction_id: "T_12345",
		value: 25.42,
		tax: 4.90,
		shipping: 5.99,
		currency: "USD"
	}
});
```

{% endcode %}
{% endhint %}

In case you would like to track more conversions than just a purchase or you are sending purchases to your `dataLayer` in a format which is different from the example above, you can.

{% hint style="info" %}
It is possible to track any number of conversions by pushing `conversion`event int the `dataLayer`.
{% endhint %}

12. If you want to send additional conversion, these are the parameters you need to send in the conversion event:

* `conversionType` - What type of conversion it is.
* `converisonValue` - the value without tax in specified currency
* `currencyCode` - Three letter ISO-4217 code of currency
* `conversionId` - an optional parameter which we recommend using in case you want to identify unique conversions later.

{% code lineNumbers="true" %}

```
dataLayer.push({
  'event' : 'conversion', 
  'conversionId': 'T_12345', // optional
  'conversionType': 'goal1', 
  'conversionValue' : 123, 
  'currencyCode' : 'CZK'
});
```

{% endcode %}

{% hint style="info" %}
Any other event you track can be also set to be treated as a conversion but it needs to be set up in Roivenue app as well as in the `roivenue.tracking.config` variable so please contact your Account Manager if you would like to use this option.
{% endhint %}

### Extra Step for Single Page Applications ONLY

13. If you have a single page website you need to inform us about page views by pushing `page_view` event into the `dataLayer`.

### Other Information

{% hint style="info" %}
If ‘user’ object is set in any event item in `dataLayer`, we use the `user.id` as the unique user identifier. This is then used for identifying users and connecting their path across multiple devices. Eg:

```
dataLayer.push({'user' : {'id':123}});
```

{% endhint %}

{% hint style="warning" %}
The User ID should not be a personal sensitive information. For privacy protection reasons it is recommended to use an artificial identifier or a hash.
{% endhint %}

## Implementation for Custom Consent Management Solution

### Prerequisites <a href="#prerequisites" id="prerequisites"></a>

* **Property ID -** You will need this to set up your script correctly. Contact your account manager to obtain it.

### Initial Setup

1. Download the GTM container [here](https://roipublic.blob.core.windows.net/tagmanager/GTM-RM-custom-consent.json).
2. Go to your GTM (at <https://tagmanager.google.com/> )
3. Go to Admin tab select “Import container”, select the container file you have downloaded. Select the workspace you want to import to and set “merge” option - as on the picture bellow.

<figure><img src="https://4279879158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MGvvrlVUvq4TNL0oYP6%2Fuploads%2FaTY9Gv1AE9Q8CE8PLxbD%2Fimage.png?alt=media&#x26;token=a4f32b27-cd9b-4847-9281-a1414b001619" alt=""><figcaption><p>Always set the import to Merge!</p></figcaption></figure>

4. Go to section “Variables”
5. Click on `roivenue.tracking.config` and change the values in the JSON object:
   1. `property_id` - Insert a Property Id provided by your account manager
   2. `api_url` - Check that "<https://tr.roivenue.com>” is filled in.
   3. `currency_code` - the default currency code that will be used for tracking purchases used in case that the currency is not specified in purchase object
   4. `event_types` - leave this blank unless otherwise agreed with your Account Manager.

<figure><img src="https://4279879158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MGvvrlVUvq4TNL0oYP6%2Fuploads%2F7SHu5evZh9qjOeYMm6ni%2Fimage.png?alt=media&#x26;token=216a7a0c-9532-4406-b2cd-f437f4580862" alt=""><figcaption><p>Fill in all the needed information</p></figcaption></figure>

### Setting up Triggers

{% hint style="info" %}
In this step, you are setting up when Roivenue Measurement script should run. By default it runs **with every page view.**
{% endhint %}

6. Navigate to Tags section.
7. Select `roivenue.tracking` code.
8. Go to the section “Triggering” and add all triggers when you want Roivenue Measurement script to run
9. that fire on all your conversion types and all events indicating a change in consent.

{% hint style="success" %}
The expected additional triggers are those which fire on all of your **conversion events** and also a trigger indicating a **change in consent** from a visitor. (By including this, you can switch between cookie and anonymous tracking within one session, if the consent is collected after the start of that session.)
{% endhint %}

<figure><img src="https://4279879158-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MGvvrlVUvq4TNL0oYP6%2Fuploads%2Fpj9IgQAgUfzc5a1kPoFV%2Fimage.png?alt=media&#x26;token=0c45fc36-1896-482c-b4e4-68dd6516b3c0" alt=""><figcaption><p>Add all necessary triggers</p></figcaption></figure>

### Setting up Consents and Anonymous Tracking

{% hint style="info" %}
Roivenue Anonymous Tracking can be used to track users without using any cookies and to tracks users in a limited scope.
{% endhint %}

10. Go to Variables.
11. Open the `roivenue.tracking.enabled`
12. Set up the variable in a way that it will return “True” in case the visitor should be tracked (either in a cookie mode or anonymous mode, this will be set up later). In a case you want to completely exclude user from tracking, this variable should return “False”
13. Open the `roivenue.tracking.persistence` variable.
14. Set it up in a way it returns `localStorage+cookie` in case you want to measure a user using cookies. If you want to measure this user in an anonymous mode, this variable should return `sessionStorage`.
15. When a user changes his consent, you should reflect this change in the value returned by `roivenue.tracking.persistence` and potentially also in the `roivenue.tracking.enabled` depending on your implementation.

{% hint style="warning" %}
You are using a custom consent management system and because of that, the steps above are more generic and you need to implement it using outputs from that CMS.
{% endhint %}

{% hint style="warning" %}
As we only act as a data processor, you are responsible for setting up the Roivenue Measurement in line with applicable legislation in your country.
{% endhint %}

### Setting up Conversions Tracking

{% hint style="info" %}

If you already have `ecommerce.purchase` event in `dataLayer`, you do not need to implement anything because we will use the following fields to track a **purchase** conversion.

* `value` - the conversion value
* `tax` - the tax
* `currency` - three letter ISO-4217 code of currency
* `transaction_id` - the transaction ID

And we save them into these variables in Roivenue:

* `conversionType`: 'purchase'
* `conversionId`: transaction\_id
* `conversionValue`: value - tax
* `currencyCode`: currency

This is how the event in your `dataLayer` should look like.

{% code lineNumbers="true" %}

```
window.dataLayer.push({
	event: 'purchase',
	ecommerce: {
		transaction_id: "T_12345",
		value: 25.42,
		tax: 4.90,
		shipping: 5.99,
		currency: "USD"
	}
});
```

{% endcode %}
{% endhint %}

In case you would like to track more conversions than just a purchase or you are sending purchases to your `dataLayer` in a format which is different from the example above, you can.

{% hint style="info" %}
It is possible to track any number of conversions by pushing `conversion`event int the `dataLayer`.
{% endhint %}

12. If you want to send additional conversion, these are the parameters you need to send in the conversion event:

* `conversionType` - What type of conversion it is.
* `converisonValue` - the value without tax in specified currency
* `currencyCode` - Three letter ISO-4217 code of currency
* `conversionId` - an optional parameter which we recommend using in case you want to identify unique conversions later.

{% code lineNumbers="true" %}

```
dataLayer.push({
  'event' : 'conversion', 
  'conversionId': 'T_12345', // optional
  'conversionType': 'goal1', 
  'conversionValue' : 123, 
  'currencyCode' : 'CZK'
});
```

{% endcode %}

{% hint style="info" %}
Any other event you track can be also set to be treated as a conversion but it needs to be set up in Roivenue app as well as in the `roivenue.tracking.config` variable so please contact your Account Manager if you would like to use this option.
{% endhint %}

### Extra Step for Single Page Applications ONLY

13. If you have a single page website you need to inform us about page views by pushing `page_view` event into the `dataLayer`.

### Other Information

{% hint style="info" %}
If ‘user’ object is set in any event item in `dataLayer`, we use the `user.id` as the unique user identifier. This is then used for identifying users and connecting their path across multiple devices. Eg:

```
dataLayer.push({'user' : {'id':123}});
```

{% endhint %}

{% hint style="warning" %}
The User ID should not be a personal sensitive information. For privacy protection reasons it is recommended to use an artificial identifier or a hash.
{% endhint %}
