How to implement the Transaction tag

AB Tasty lets you save the data related to transactions on your website (e.g., transaction amounts, payment methods, number of purchased items, average cart value, item price, etc.). 

This data is available in the reports of each campaign in the form of indicators or filters. Please refer to the Campaign report guide for further information.

The first thing to know about the transaction tag is that it is not a tag itself (as the generic tag can be) but rather a revenue tracker that must be placed on the order confirmation page.

To send transaction data to AB Tasty and display it in the reports, you need to add the transaction tag to your purchase confirmation page after the generic AB Tasty tag.

Please note that transactions will only be linked to the campaign the user has seen. 

There are 3 ways to implement the transaction tag: 

Once the transaction tag is implemented on your website, you can go ahead and run the QA process. For further information, refer to How to QA the Transaction Tag.

 

Option 1: The Transaction Tag Generator

(Medium level of complexity)

Transaction tag generator enables you to implement your transaction tag easily as you just need to indicate where to find the transaction data. The transaction tag will be automatically embedded in the generic tag with no need for creating or modifying any code. 

 

Benefits

👉 Debugging is made easier since we have more visibility on what has been set up compared with a code you have to add to your source code or your TMS.

👉 The transaction tag generator is based on data layer variables or CSS selectors you have defined. These parameters are more stable than using a custom code. 

 

Heads up

👉 You must implement and find the exact variable names to make the transaction tag generator work.

👉 If the variables are modified on your website, it will also impact the transaction tag collection. You will need to adapt the transaction tag implementation accordingly.

When implementing the transaction tag directly in the settings, you do not need to implement it again into your source code.

 

Configuration

You can implement your transaction tag using one of the three following methods:

👉Datalayer mode: by declaring the variables from your data layer containing the transaction-related information.

👉Selector mode: by declaring the CSS selectors containing the transaction-related information.

👉Expert mode: by completing the code snippet.

 

To use the data layer mode, you first need to integrate your data layer into your AB Tasty account settings.

 

Depending on the settings you specified, a JavaScript code is created and will be automatically included in the AB Tasty tag. This code is updated each time the configuration is modified and saved with the tag up-to-date.

First, you need to create an affiliation, which coincides with the name you will give to your transaction tag. 

How_to_Implement_the_Transaction_Tag_01.png

Then, you must specify the URL(s) of your website on which the transaction information is available, such as the confirmation page. 

 

How_to_Implement_the_Transaction_Tag_02.png

 

You can create as many affiliations as you want and you can edit and delete them.

You need to select the method with which you want to implement your transaction tag: 

 

Data Layer Mode

The data layer mode enables you to implement your transaction tag based on the variables defined in your data layer.

For each mandatory field, you need to enter the name of the key that will be extracted from the corresponding variable. These keys can be found in your data layer. 

For example, to fill in the transaction ID, you need to enter the key corresponding to the transaction ID you configured in your data layer. If the transaction is available in the key order_id with a corresponding value OD564, this means that you need to enter the order_id in the transaction ID field. 

 

Please note that the tag will try its best to automatically format your data to the correct data type, ie. transform a character string into a number, but some specific data conversion will not be possible. You should type in already formatted data rather than let the tag automatically convert them to avoid any issues. Please refer to this documentation for further information about expected data types.

 

How_to_Implement_the_Transaction_Tag_03.png

 

For further information about the data layer, please refer to our integration guide

 

Selector Mode

The selector mode can be used if the transaction data is available directly in the code of your confirmation page. In this case, you need to fill in each field with the corresponding CSS selector that can be used in the document.querySelector function.

The item count number (icn) coincides with the total number of items purchased during the transaction. It can be calculated via three different methods.

Example:

{
"transaction_id": "transac1234",
"items_count": 5
"products": [
{
"name": "item 1",
"quantity": 2
},
{
"name": "item 2",
"quantity": 3
}
]}

 

👉 If your key (data layer mode) or selector (selector mode) contains the total number of purchased items, select Default.

In the code example, the key would be items_count (returns 5)

👉 If your key or selector contains unitary purchased items, select Count.

In the code example, the key would be products[] (returns 2)

👉 If your key or selector contains the quantity of each purchased item, select Sum.

In the code example, the key would be products[].quantity (returns 5)

 

Expert mode

The Expert mode enables you to implement your transaction tag via a JavaScript code.
By default, there is a code example that you can edit and replace with your own data, available in your source code or Datalayer. You also need to apply the appropriate format to your values (string, float or integer) as described in our developer portal

The transaction affiliation/name (ta), transaction id (tid), transaction revenue (tr) and item count number (icn) must be declared during transaction tag implementation. The other settings are optional, however we recommend configuring them also in order to enable the application of matching filters in the reports later on. 

 

Adding Purchased Items Data

Information related to the purchased items can be linked to each transaction to apply matching filters in the campaign reports or to use purchase-related targeting criteria. 

Purchased items data can be collected via the three available methods: Datalayer, Selector, or Expert.

  • First, select Array of items as an optional value and enter the key or selector corresponding to the array of objects of all items purchased during the transaction.

How_to_Implement_the_Transaction_Tag_04.png

In the above example, all item-related data are stored in the transactionProducts array of the data layer, on the purchase confirmation page.

How_to_Implement_the_Transaction_Tag_05.png

  • Click Add optional value:
    All the data corresponding to items’ characteristics appear as additional fields where you can insert the data layer key or selector corresponding to the item name, price, quantity, ID, and category:

How_to_Implement_the_Transaction_Tag_06.png

In this example, on the data layer, the item name can be found in the name key, the ID in the SKU key, and so on.

How_to_Implement_the_Transaction_Tag_07.png

To add the purchased items data in the Expert mode, apply the following steps: 

  1. Complete the variable corresponding to “__TRANSACTION _ITEMS_ARRAY__”.
  2. Complete all the items characteristics with their corresponding variables in tid, in, ip, iq, ic and iv. 
    Array_code_2 (1).png


Preview

The preview enables you to verify that your transaction tag has been correctly configured by showing the latest transactions registered on your website.

The Transaction Tag Generator is using universal collect data. This is why, after you have implemented your transaction tag, it may take a few hours for the first transactions to be visible in the preview.

Once the new affiliation has been saved, do not forget to refresh the tag (in the header right) to be sure that all your modifications are taken into account in production.

For each transaction, the values corresponding to the keys you specified in your transaction tag are displayed:How_to_Implement_the_Transaction_Tag_08.png

If the preview is still empty after several hours, it probably means that one of the fields has not been implemented correctly. Please, check the URL page and all the fields again to be sure that everything is set up correctly. If not, you should ask your technical team or your dedicated AB Tasty consultant to do it for you. 

 

Option 2: A dedicated code

(Advanced Level of Complexity – A Developer is Needed)

You can create and code your transaction script you will then integrate into your confirmation page’s source code or your Tag Management System (e.g GTM or Tag Commander). 

The transaction tag features two parts: the first part enables the transmission of information related to the transaction (ID, name, amount, delivery fees, etc.) and the second part enables the transmission of item or product details related to purchases made by customers visiting your website.

 

You can use the code template provided below. 

Follow the steps below to implement the transaction tag:

  1. Copy all of the code below and paste it into your confirmation page.

 

Heads up ⚡

This is the generic transaction tag. Variables are specific to your website.

 

// transaction tag

<script>

window.abtasty.send(“transaction”, {

  tid: __TRANSACTION_ID__, // Format: STRING, value example: “OD564"

  ta: __TRANSACTION_NAME__, // Format: STRING, value example: “Purchase”

  tr: __TRANSACTION_REVENUE__, // Format: FLOAT, value example: 15.47

  ts: __TRANSACTION_SHIPPING__, // Format: FLOAT, value example: 3.5

  tt: __TRANSACTION_TAXES__, // Format: FLOAT, value example: 2.60 

  tc: __TRANSACTION_CURRENCY__, // Format: STRING, vLicalue example: “EUR”      

  tcc: __TRANSACTION_COUPON_CODE__, // Format: STRING, value example: “Coupon”

  pm: __TRANSACTION_PAYMENT_METHOD__, // Format: STRING, value example: “Paypal”

  sm: __TRANSACTION_SHIPPING_METHOD__, // Format: STRING, value example: “Fedex”

  icn: __TRANSACTION_ITEM_COUNT_NUMBER__ // Format: INTEGER, value example: 12

});

</script>

// transaction items tag

<script>

window.abtasty.send(“item”, {

  “tid”: __TRANSACTION_ID__, // Format: STRING, value example: “OD564”

  “in”: __TRANSACTION_ITEMS[i].ITEM_NAME__, // Format: STRING, value example: “Shoe”

  “ip”: __TRANSACTION_ITEMS[i].ITEM_PRICE__, // Format: FLOAT, value example: 3.5

  “iq”: __TRANSACTION_ITEMS[i].ITEM_QUANTITY__, // Format: INTEGER, value example: 4

  “ic”: __TRANSACTION_ITEMS[i].ITEM_CODE__, // Format: STRING, value example: “SKU47”

  “iv”: __TRANSACTION_ITEMS[i].ITEM_CATEGORY__ // Format: STRING, value example: “Blue”

});

</script>

 

  1. Replace the __TRANSACTION_[OBJECT]__values with your data, available in your source code or data layer.
  2. Apply the appropriate format to your values (string, float, or integer) as described in our developer portal
  3. Create a loop in the code so that it is triggered as many times as there are items in the transaction.

 

For Transaction Items, the key/value pair is unique to each item of the transaction.

If the transaction includes more than one item, the Transaction Items must be sent as many times as there are items in the transaction.

The Transaction Items must be sent independently for each item.

 

Recommendations When Implementing in the Source Code

When implementing in the source code, we recommend the following:

  • the names of transaction and item parameters must not be modified;
  • when replacing the__TRANSACTION_[OBJECT]__ values, do not keep the opening or the closing double underscore `__`;
  • there should always be a comma, at the end of each line (except for the last line, for which it is not mandatory). 
  • never place double “ ” or single ‘ ’ quotes around the value of the in parameter, even if the expected format of the value is a character string;
  • implement the transaction tag at the bottom of the page - far from the generic tag. The transaction tag does need to be triggered after the generic tag. However, placing it at the bottom of the page will ensure the generic tag has fired already and that all values the transaction tag relies on have loaded as well.

 

Option 3: Via a Tag Management System

When implementing via a Tag Management System, we recommend the following:

  • always implement the generic tag in the first position at the top of the page, then execute it. 
  • implement the transaction tag in the second position, i.e after the generic tag.
    Otherwise, the AB Tasty undefined error message will be displayed.

Was this article helpful?

/