# Implementation without 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 %}

### 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.

### Visits tracking on all pages <a href="#visits-tracking-on-all-pages" id="visits-tracking-on-all-pages"></a>

1. Insert this entire code on every page inside `<head> </head>` element.

{% code lineNumbers="true" %}

```
<!-- BEGIN Roivenue Measurement -->
<script>
  var rm_config = {
    property_id : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    api_url: "https://tr.roivenue.com", 
    autocapture: true
  };
</script>  
<script src="https://tr.roivenue.com/static/init_v2.js"></script>
<!-- END Roivenue Measurement -->

```

{% endcode %}

2. Adjust the `property_id` - insert the ID you have from your account manager.

### Start Tracking Events

3. To start tracking events, call the `startMeasurement` function of the global `$rm` object:

{% code lineNumbers="true" %}

```
$rm.startMeasurement();
```

{% endcode %}

{% hint style="info" %}
Tracking events will start only after you call the `startMeasurement` function. This allows you to evaluate user consent with cookies first and start tracking events only after that.
{% endhint %}

{% hint style="warning" %}
**Important  - This is a frequently missed step**\
When a user visits your page for the first time, he is probably presented with a cookie banner. You need to send an event **immediatelly** after they interact with the cookie banner! If you send a next event only after they go to next page, you lose the source of the visit **forever** and as a result you will not know what was the original source of a conversion when they make a purchase in the future.
{% endhint %}

{% hint style="info" %}
When script above is included, and `$rm.startMeasurement();` is called, it automatically tracks page views and page leave events. The script will automatically track traffic source information from HTTP referrer and UTM parameters, device type and other useful information.
{% endhint %}

{% hint style="info" %}
After tracking script is initialized (by code snippet above), custom events can be then tracked by calling `capture()` function of `$rm` global object (see Conversion Tracking section for an example).
{% endhint %}

{% hint style="info" %}

### Disabling measurement <a href="#disabling-measurement" id="disabling-measurement"></a>

Once measurement has been started by calling `$rm.startMeasurement()` it is enabled and captures all events. Measurement can then be stopped by calling `$rm.stopMeasurement()`.

`$rm.stopMeasurement();`

Calling this method disables measurement and no further events will be captured even when calling `$rm.capture()` or `$rm.identify()`.
{% endhint %}

### Configuration of Consent and Anonymous Tracking <a href="#configuration-of-consent-and-anonymous-tracking" id="configuration-of-consent-and-anonymous-tracking"></a>

{% hint style="info" %}
The `startMeasurement` function has an optional parameter which is a configuration object.

{% code lineNumbers="true" %}

```
$rm.startMeasurement({ /* options */ });
```

{% endcode %}

**Persistence**

{% code lineNumbers="true" %}

```
$rm.startMeasurement({ persistence: 'localStorage+cookie' });
```

{% endcode %}

The `persistence` option allows you to specify how user data is stored in the browser. The `persistence` option can have one of the two values:

* `persistence: "localStorage+cookie"` (default): Cookies are used in this case
* `persistence: "sessionStorage"`: Stores everything in `sessionStorage`, cookies are not used.
  {% endhint %}

4. If you have a full consent from your website visitor, we recommend using the default settings of `persistence`.
5. When there is a limited consent with tracking, you should set up `persistence` to `sessionStorage`

{% code lineNumbers="true" %}

```
$rm.startMeasurement({ persistence: 'sessionStorage' });
```

{% endcode %}

6. To completely exclude user from tracking, the `startMeasurement` function should not be called at all.

{% hint style="info" %}
When a user changes his consent with cookies at any point, this change can be passed to Roivenue Measurement using `setConfig` function. This function has a single parameter which is a configuration object with the same structure as in `startMeasurement` function.

```
$rm.setConfig({ /* options */ });
```

`setConfig` function can be called only after `startMeasurement` function has been called.

An example of calling `setConfig` to set the persistence to a cookie:

```
$rm.setConfig({ persistence: 'localStorage+cookie' });
```

{% 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 %}

#### Additional Settings for Anonymous Tracking with Multiple domains

{% hint style="info" %}
This section is relevant only to businesses which have a site splitted into multiple domains. It means some sort of split like: **shop.example.com** and then **checkout.example.com** and your customers are automatically redirected between those subdomains as they shop. If you are not using subdomains this way, skip this part and continue to [Conversions Tracking](#conversions-tracking.1)
{% endhint %}

1. You need to configure a property in the `rm_config` object
   * `write_cross_domain_info` - By default, it is set to `false`,change it to `true`
     * The session id will be inserted into the URL of the current web page and will be passed as a referrer URL to subsequent web pages.&#x20;
2. You need to insert a following meta tag for referrer policy into the source web page:&#x20;
   * `<meta name="referrer" content="no-referrer-when-downgrade" />`&#x20;
     * This step makes it possible to pass the full URL in the referrer URL.
     * The destination web page automatically reads the session id from the referrer URL.

The destination web page automatically reads the session id from the referrer URL.

### Conversions Tracking <a href="#conversions-tracking.1" id="conversions-tracking.1"></a>

Next, we need to capture all conversions created by your customers.

7. To do that, call capture conversion to track an e-commerce purchase event:

{% code lineNumbers="true" %}

```
$rm.capture('conversion', {
  conversionType: 'purchase', //there may be a different type like 'userRegistration' etc.
  conversionId: 'XXX12346', //unique conversion ID 
  conversionValue: 123.5, //decimal number - monetary value of the conversion (optional)
  currencyCode: 'XXX' //Three letter ISO-4217 code of currency, (required if conversionValue is specified)
});
```

{% endcode %}

{% hint style="info" %}

#### Multiple Conversions Setup <a href="#multiple-conversions-setup.1" id="multiple-conversions-setup.1"></a>

To track other conversion type events, you can easily track a ‘conversion’ event exactly the same as described above and just change the `conversionType`.
{% endhint %}

### User Identification <a href="#user-identification.1" id="user-identification.1"></a>

{% hint style="info" %}
This step is optional
{% endhint %}

We can use User ID to track users across devices. This ID is typically available only for users which logged in on your website.

8. Whenever the user logs in or makes a purchase that you are able to connect with a unique user identifier, call this:

{% code lineNumbers="true" %}

```
$rm.identify('[user unique id]')
```

{% endcode %}

{% 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 %}

### Additional Changes for Single Page Applications <a href="#additional-changes-for-single-page-applications.1" id="additional-changes-for-single-page-applications.1"></a>

{% hint style="info" %}
Most e-commerce solutions use standard navigation between pages and you can skip this section. But if your website is a javascript single page application, then there need to be some changes.
{% endhint %}

9. Set the `rm_config.autocapture` to `false`on all pages.
10. To track pageviews, call capture function after every navigation (when page location changes):

{% code lineNumbers="true" %}

```
$rm.capture('pageview', {});
```

{% endcode %}

{% hint style="info" %}

#### Tracking Other Events <a href="#tracking-other-events.1" id="tracking-other-events.1"></a>

Roivenue Measurement supports tracking of other on-site events as well. If you are interested in custom implementation, let us know.
{% endhint %}
