Order Tracking Analytics (Script)

The Duel Tracking Analytics Script allows us to track affiliate link and promo code usage, loyalty and orders from UGC links on your eCommerce site.

Average Integration Time: 10 minutes - 2 hours

🛍️ Included in our Shopify App

Instructions
Element Key
Encrypted data
Node.js
Affiliate Link - Order Attribution Notes

Installation Instructions

Step 1

Please incorporate the following snippet into all of your pages:

<script async src="https://vision.duel.me/duel-analytics.js"></script>

Step 2

Please incorporate the following snippet into your checkout/done or success page:

<script>
window.duel=window.duel||function(){(duel.q=duel.q||[]).push(arguments)};

duel('analytics:attribution', "slug={slug}&order={number}&total={total}&total_gross={total_gross}&currency={currency}&email={email}&email={email}&promo={promo}&customer_id={customer_id}&new_customer={new_customer}");
</script>

Elements Key & Notes

  • {slug} → should be replaced with your brand slug provided by Duel or you can find yourself by logging into the dashboard and heading to settings (top right) under Short ID
  • {number} → should be replaced with the attribute for the order number
  • {total} → should be replaced with the attribute for the order total
  • {total_gross} → should be replaced with the attribute for the gross order total (order total before any promotional discounts are applied)
  • {currency} → should be replaced with the attribute for the currency of that order
  • {email} → should be replaced with the email of the customer who placed the order
  • {new_customer} → should be replaced with y or true if the order was placed by a new customer
  • {customer_id} → should be replaced with the id of the the customer who placed the order, used to track life time value
  • {points} → can be sent when you want to allocate specific points for an order (i.e. when an order is placed by a new customer)
  • {commission} → can be sent when you want to allocate specific commission for an order (i.e. when an order is placed by a new customer)
  • {commission_currency} → should be sent along with the commission figure above
  • {promo} → should be replaced with the promo used in this order (if any). This should be the actual promo code (ANDY123), not the promo code name (Advocate Code).
    • If you want to provide multiple promo codes, add “&promo={promo}” for each additional promo code to the data like the example provided.

Example: 

<script>
window.duel=window.duel||function(){(duel.q=duel.q||[]).push(arguments)};

duel('analytics:attribution', "slug=ab&order=123456&total=149&total_gross=200&currency=USD&email=customer@example.com&customer_id=customer123&new_customer=y&promo=PROMO123&promo=PROMO456");
</script>

Step 2 - Alternative Method

You can also provide the data as an object:

<script>
window.duel=window.duel||function(){(duel.q=duel.q||[]).push(arguments)};

duel('analytics:attribution', {
  slug: '{slug}',
  order: '{number}',
  total: '{total}',
  total_gross: '{total_gross}',
  currency: '{currency}',
  email: '{email}',
  promo: '{promo}',
customer_id: '{customer_id}',
 new_customer: '{new_customer}',
});
</script>

Refer to the above Elements Key & Notes.

For multiple promo codes, provide them as an array like the example below.

Example: 

<script>
window.duel=window.duel||function(){(duel.q=duel.q||[]).push(arguments)};

duel('analytics:attribution', {
  slug: 'ab',
  order: '123456',
  total: '149',
  total_gross: '200',
  currency: 'USD',
  email: 'customer@example.com',
  promo: ['PROMO123', 'PROMO456'],
 customer_id: 'customer123',
 new_customer: 'y',
});
</script>

All characters in emails should be url encoded i.e "@" should be "%40"
Further information here Mozilla encodeURIComponent()

Send Encrypted Data

Step 1

Create API user credentials in the dashboard under Settings > API Users (https://app.duel.me/app/settings/open-api)

If you do not have an operator login for the duel dashboard please reach out to your Brand Success Manager

Step 2

Use the created API user credentials in order to send the order information.

You will need to pass the slug (Short ID), then the "username" (from the API user you created) and then use the password (from the API user you created) in order to encrypt all the order information and include them in "payload".

Example:
Without encryption:

GET /attribution?slug=z9&order=358227&promo=&total=99.00&currency=EUR&email=foo%40gmail.com

With Encryption

 GET /attribution?
slug=ab &
username=123 &
payload=bm9uY2U9ZTdiMzcyODE0MmI3ZGI5NjQ2MDFjMWE5M2IxNDNjYmEmaWQ9MTE3ODkyNiZlbWFpbD12YWxsZW50MjUlNDBtYWlsLnZtaS5lZHUmbmFtZT1OaWNvbGF1cyUyMFZhbGxl

Node.js Implementation

'use strict';
const crypto = require('node:crypto');

const API_USER_SECRET = '<SECRET>';
const API_USER_USERNAME = '<USERNAME>';
const PARAMS = {
slug: '<SLUG>',
// ...all usual order parameters
};

// Create 12 byte initialisation vector.
const initVector = crypto
.randomBytes(12);

// Create key with first 32 bytes of secret (for cipher).
const key = API_USER_SECRET
.slice(0, 32);

const cipher = crypto
.createCipheriv(
'aes-256-gcm',
key,
initVector,
);

const buffer = Buffer
.concat([
cipher.update(new URLSearchParams(PARAMS).toString(), 'utf8'),
cipher.final(),
]);

// Prepend initVector and 16 byte auth tag.
const payload = Buffer
.concat([
initVector,
cipher.getAuthTag(),
buffer,
])
.toString('base64url');

console.log(new URLSearchParams({
slug: PARAMS.slug,
username: API_USER_USERNAME,
payload,
}).toString());

Affiliate Link - Order Attribution Notes

Affiliate links operate on last click attribution, this means that when a customer clicks on an affiliate link and makes a purchase, the affiliate who generated the link will receive credit for the sale. This attribution model gives credit to the last affiliate link clicked by the customer before making the purchase.

By using the provided code snippet in the checkout script, you have the option to adjust the default attribution time of 30 days to a specific duration. For example, you can set the storageMinutesToLive to 20160 minutes (14 days) to determine that the last affiliate link clicked within the 14-day period will be attributed with the sale.

duel('analytics:config', 'storageMinutesToLive', 20160);

Example: 

<script>
window.duel=window.duel||function(){(duel.q=duel.q||[]).push(arguments)};
duel('analytics:config', 'storageMinutesToLive', 20160);
duel('analytics:attribution', "slug={slug}&order={number}&total={total}&total_gross={total_gross}&currency={currency}&email={email}&email={email}&promo={promo}&customer_id={customer_id}&new_customer={new_customer}");
</script>