Overview

Tracking JS

What is it?

TrackingJS is a JavaScript library that serves the purpose of rewarding users for certain actions they do on your website. By simply adding a Javascript snippet and configuring it, you can send us relevant data that is required for Aklamio to pay a reward for a rewardable action or event.

Get started

Include the script where the rewardable action takes place.

For example, if a user should be rewarded when a contract is signed or a product is purchased, the script has to be implemented after that event occurs (normally, in the thank you page).

This is a standard example of how our TrackingJS looks like. For a successful request, it needs at least 4 required parameters: partnerID, orderRef, checkoutLocation and itemID. The other implemented fields are extremely important in case Reward Rules are based on Price, Category and so on.

Click here if you want to see more examples on how you can set up TrackingJS.

Check the following example to see how to implement the script. Remember to replace the values with your own.

              <script src="https://api.aklamio.com/tracking.min.js"></script>
<script type="text/javascript">
  function createRequest() {
    try {
      var partnerID = 'z28v762bsfe7c5611272600ebeb08634'; // --> Identifies your program within Aklamio. This parameter value is provided by Aklamio.
      var orderRef = 'LQ29961J725'; // --> A reference to the order to trace it back. This parameter value is provided by you.
      var checkoutLocation = '/checkout/cart'; // --> The location of the checkout page. This parameter value is provided by you.
      var request = com.aklamio.sales.createRequest(
        partnerID,
        orderRef,
        checkoutLocation,
      );

      request.setAID('ar833076d0d70d0a285dd3b34a972f8d2b3cb4fc6f66eb9af99121fced1d96e009'); // --> The AID is a direct reference to the Aklamio event (e.g. referral) that led to this sale. The AID is provided in the URL when a user is redirected back to your page by clicking on a referral link. Note that AID takes precedence over any other Aklamio tracking mechanism (coupon, cookies, etc.).

      var itemID = '178834'; // --> The ID of the item that is being purchased. This parameter value is provided by you.
      var item = com.aklamio.sales.createItem(itemID);
      item.setPrice(1400); // --> Price of the product bought. It must be sent in cents.
      item.setCategory('iphone'); // --> Name of the Product Category registered with Aklamio Backend sent parsed into variable.
      item.setRewardCategory('iphone_reward_category'); // --> Name of the Reward Category registered with Aklamio Backend sent parsed into variable. It is a dynamic field. Someone from Aklamio will send a Matrix containing all Categories registered and agreed with Comercial department.

      request.addItem(item);
      request.send();
    } catch (e) {
      console.error(e);
    }
  }
  createRequest();
</script>
            

After you include the script with your own replaced values in your web page, check the browser console. If you see the message The request passed the validation successfully, congratulations!. Your request was sent to Aklamio.

Request Parameters

The Sales Request object is the main object that you will use to track your users' purchases. This is where you store the items and general information that you are going to send to Aklamio when you execute the send function.

Field name
Description
Type
Mode
partnerID
Identifies your program within Aklamio. If you have several programs (e.g. countries), a distinction is made via the partnerId.
string
required provided by Aklamio
orderRef
A reference to the order that allows you to trace back the order, has to be unique and is later on used for the validation of sales. Note that special characters are not allowed (e.g. ,<>?;:'"\|[{]}!#$%^&*()=+`~).
string
required
checkoutLocation
Defines the checkout, in case there are several checkouts, usually one page => one checkout location.
string
required
items
Array of items in the order. You must include at least 1 item in the request.
Array
required
aid
The AID is a direct reference to the Aklamio event (e.g. referral) that led to this sale. The AID is provided in the URL when a user is redirected back to your page by clicking on a referral link. Note that AID takes precedence over any other Aklamio tracking mechanism (coupon, cookies, etc.).
string
optional
encryptedEmail
This is only relevant for Native Cashback Sales - By setting this parameter the reward will be assigned to the encryptedEmail provided by the user. The encryption method must be AES-256-CBC signed with HMAC-SHA1 and we will use this to sign up users to Aklamio for "Native Cashback". Note that email and encryptedEmail should not be set in the same request object.
string
optional
email
The email of the follower. It represents the referred user. Notes:
¹ email and encryptedEmail should not be set in the same request object;
² email is not required for Keep use case;
string
optional required if coupon is set and use case is Share or Give
coupon
The Coupon is also a direct reference to the Aklamio referral that led to this sale. The Coupon is provided in the URL when a user is redirected back to your page by clicking on a referral link. You can take it from there dynamically or ask your user to paste the Coupon code manually (Reward Codes use case) so you can pass it on to the script. Note that email is required when using a coupon and the use case is Share or Give.
string
optional
trackingAttribution
This value indicates whether the sale was already attributed to another channel/competitor (and therefore it is not eligible for a reward at Aklamio)
boolean
optional
metainfo
Here, you can provide any additional information about the tracked sale that might be important for you for further evaluation. We will not evaluate this info, but we can provide it in reports.
Object
optional

Check the full Request object:

Request

Sales Item

The Item object is the main object that you will use to create items from a sales event that you want to track. This is where you store the item information that you are going to send to Aklamio when you execute the send function from the Sales Request object.

Field name
Description
Type
Mode
id
Item Identification of the Product bought and registered within Aklamio backend sent parsed into variable. It is a dynamic field -> please ensure that Item ID can be used for validation
string
required
name
Product name registered within Aklamio backend sent parsed into variable. It is a dynamic field. Someone from Aklamio will send a Matrix containing all Names registered and agreed with Comercial department
string
optional
price
Price of the product bought. It must be sent in cents e.g: If a product was bought for $14.00 it needs to be sent as set.Price(1400)
number
optional
category
Name of the Product Category registered with Aklamio Backend sent parsed into variable. It is a dynamic field. Someone from Aklamio will send a Matrix containing all Categories registered and agreed with Comercial department. Note that special characters are not allowed (e.g. /,<>?;:'”\|[{}]!@#$%^&*()=+`~).
string
optional
rewardCategory
Name of the Reward Category registered with Aklamio Backend sent parsed into variable. It is a dynamic field. Someone from Aklamio will send a Matrix containing all Categories registered and agreed with Comercial department. Note that special characters are not allowed (e.g. /,<>?;:'”\|[{}]!@#$%^&*()=+`~).
string
optional
rewardFixed
Indicates the Fixed Reward value to be paid out to the user. Needs to be send in cents so 14.00 will be 1400.
number
optional
rewardPercent
Indicates the % of a Reward will be paid out based on the total item basket.
number
optional

Check the full Item object:

Item

Category configuration

In the category property of the item, you need to provide the exact name that you configured in our Partner Interface system. For instance, in case you want to reward a customer for the category "135167", you need to provide the value "135167" in the category property.

            var item = com.aklamio.sales.createItem('1234-5678');
item.setCategory('135167');
request.addItem(item);
          

This is how the category configuration looks like in Partner Interface:

Encrypted Email

Encrypted Email must only be used in Native Cashback campaigns. Remember that you can NOT use email and encryptedEmail properties in the same request.

In order to implement Native Cashback tracking, the customer needs to add the encrypted version of the users email address as a parameter to the tracking snippet.

How to get the encrypted email value

  1. As an Aklamio customer, you will receive a native cashback key in a secure way.
  2. Use that native cashback key to encrypt the users email address using one of the following code snippets:
  3. Use the encrypted email value as a parameter in the setEncryptedEmail function of the Sales Request object.
                    request.setEncryptedEmail("encrypted_email_value");
                  

Loading TrackingJS asynchronously

Do not use this approach if you are including TrackingJS snippet in any tag manager. (Google Tag Manager, Adobe Launch, etc.)

It is often required for performance reasons to load javascript files asynchronously, so you do not have to wait until the file is loaded before executing the code in your website. This is the reason why we can also use the defer attribute in the script tag.

Example

            <script defer src="https://api.aklamio.com/tracking.min.js" onload="createRequest();"></script>
<script type="text/javascript">
  function createRequest() {
    <!-- Your code here -->
  }
</script>
          

Testing

When you first implement your script, you likely want to test it to see that everything is working perfectly before you send real data to Aklamio. The best way for doing this is using our test parameter. This way, we can identify if the data you are sending is real or just a test. To achieve this, add test parameter to the request in the following way:

            request.setTest(true);
          

FAQ

Q: How can I check that my request was sent successfully?

A: After executing request.send() function, you can check the browser console. You will see a Request was sent successfully message if the request was sent correctly. If not, check your console for more information. (Javascript errors, validation errors, etc.)

Q: Where in my application should I include the TrackingJS code?

A: It will depend on your application structure, but normally, the script and the code will be included in the head or body of your HTML document.
If you are using any tag manager, you will probably include the script in the corresponding configuration place of the tool.

Possible errors

Uncaught ReferenceError: 'variable' is not defined
This happens when you try to use a variable that is not defined in any part of your application.
errors: "Partner id must be a 32 digit hex."
Make sure that you have set the partner id with a valid format.
errors: "Email is not a valid email."
Make sure that you have set the the email with a valid format.
errors: "Encrypted email encryptedEmail and email must not be both specified"
If you are using native cashback, make sure you are only including encryptedEmail property in the request. You cant include email property in this case.
errors: "Encrypted email should follow the pattern: [(base64 payload)--(hex digest of sha1 signature)]"
Make sure you are inserting the encrypted email with a correct format.

Examples

Check the following complete examples to see how to use TrackingJS.