# Conversion tracking

| METHOD              | IMPLEMENTATION COMPLEXITY       | WHEN TO USE?                                                                                                  |
| ------------------- | ------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| Auto-capture        | Trigger adjustment              | Customizations of tracked events are not necessary.                                                           |
| Send event directly | One custom HTML tag and trigger | There is a need to adjust payload of conversion events.  Giving you absolute freedom in the payload you send. |
| Translation tags    | One custom HTML tag and trigger | When changes to otherwise captured properties are needed. Adding additional properties is not supported.      |

{% hint style="danger" %}
These approaches can be combined, but make sure not to double-count any conversions while doing so.
{% endhint %}

### Auto-capture

If you have followed the Main Implementation and want to track purchases from the e-commerce module, you must only ensure proper triggers for the main tracking tag. This typically requires adding a purchase event as a trigger for it.

{% content-ref url="/pages/Ckhygo6iaznirfllKwk3" %}
[Main Implementation](/roivenue-resources/howto/roivenue-measurement-implementation/implementation-through-gtm/main-implementation.md)
{% endcontent-ref %}

### Send event directly

Another option is to use the Roivenue global tracking object to capture events directly. This is handy for customizing the purchase event's fields or capturing custom conversions. Before implementing this logic, remove purchase events from the automatically collected events in the roivenue.tracking.config variable.

This is what a script for tracking this event can look like:

```javascript
posthog.Roivenue.capture('conversion', {
    conversionType: 'MyCustomPurchase', 
    conversionId: {{conversionId}}, 
    conversionValue: {{conversionValue}}, 
    currencyCode: {{currencyCode}},
    customField1: {{...someProps}}
});
```

<figure><img src="/files/x1FLu287MAYJWF1wTchS" alt=""><figcaption></figcaption></figure>

Ensuring the main tracking script is initialized before the custom event is sent is essential.

We can use a setup tag in tag sequencing or adjust the trigger. This is how a tag sequence option would look like:

<figure><img src="/files/N04g3iyE3wN8SuCzfMOE" alt=""><figcaption></figcaption></figure>

### Translation Tags

In a situation when you want to track a conversion and you already have details about the conversion in dataLayer (which may be already used by some other GTM tag) but the data structure of the conversion does not match either the Google Ecommerce or Roivenue Measurement standard, you can create a new tag that will convert the data structure or change the logic how the event is triggered. To implement this you need to:

1. Make sure the event type already in dataLayer is not listed in event\_types in roivenue.tracking.config variable. This is necessary to avoid duplicate events.
2. create a new tag that will be triggered by the event you would like to track. The tag will read the event data, translate it into roivenue format and then push a new event of type “roivenue\_measurement\_event” into dataLayer.
3. roivenue measurement tag is triggered by this event and captures it with its payload. The field type in the payload will work as the event type of the captured event.

An example of the tag is below.

<figure><img src="/files/lkGHfiwjM4FcajdPDoLE" alt=""><figcaption><p>Example of a translation tag</p></figcaption></figure>

{% hint style="info" %}
The tag is being triggered by a standard conversion trigger. The tag reads the transaction details from a dataLayer variable named transactionData. Then it pushes a new event roivenue\_measurement\_event. This would be equivalent of calling this:

{% code lineNumbers="true" %}

```
DataLayer.push({
'event' : 'conversion',
'conversionId': {{transactionData.orderId}},
'conversionType': 'purchase',
'conversionValue' : {{transactionData.orderAmount}},
'currencyCode' : {{transactionData.currency}}
});
```

{% endcode %}

`dataLayer.push({`
{% endhint %}

Here is another example of a conversion tag. Its code does not use variables but use directly contents of dataLayer. It searches for the last event of type “purchase” in dataLayer and then translates and pushes a new event.

{% code lineNumbers="true" %}

```
if (dataLayer) {
 for (var i = dataLayer.length - 1; i >= 0; i--) {
  
  var item = dataLayer[dataLayer.length - 1];
   
   if (item.event == 'purchase') {
    
    dataLayer.push({
     event: 'roivenue_measurement_event',
     type : 'conversion',
     conversionId: item.purchaseData.orderId,
     conversionType: 'purchase',
     conversionValue : item.purchaseData.orderAmount,
     currencyCode : item.purchaseData.currency 
    });
    
      break; 
     } 
    }
   }
```

{% endcode %}

The event fields needed for conversion processing are described in the **Tracking Purchases and Other Conversions** section of the [main implementation guide](/roivenue-resources/howto/roivenue-measurement-implementation/implementation-through-gtm.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.roivenue.com/roivenue-resources/howto/roivenue-measurement-implementation/implementation-through-gtm/conversion-tracking.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
