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.
,<>?;:'"\|[{]}!#$%^&*()=+`~
).
email
and
encryptedEmail
should not be set in the same request object.
¹
email
and encryptedEmail
should not be set in
the same request object;²
email
is not required for Keep use case;
email
is required when using a coupon and the use
case is Share or Give.
Check the full Request object:
A Request object returned by com.aklamio.sales.createRequest
Type: Object
(string)
: Identifies your program within aklamio. This will be provided by Aklamio.
If you have several programs e.g. countries a distinction is made via the partnerId.
(string)
: 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.
(string)
: Defines the checkout, in case there are several checkouts, usually one page
=> one checkout location.
(string)
: Indicates if a tracked sale is just a test sale. Make
sure to send this parameter to exclude the sales from performance reports.
(only if a test is placed)
(Array<Item>)
: Array of items in the order. You must include at
least 1 item in the request.
(string)
: The email of the follower. It represents the referred user.
Note that ¹ email and encryptedEmail should not be set in the same request object;
² email is not required for Keep use case;
(string)
: This is only relevant for Native Cashback
Sales - By setting this parameter the reward will be assigned to the
encryptedEmail provided of the user. The encryption method must be
AES-256-CBC signed with HMAC-SHA1 and we will use this to signup users to
Aklamio for "Native Cashback". Note that email and encryptedEmail should
not be set in the same request object.
((string | boolean))
: This value indicates whether
the sale was already attributed to another channel/competitor (and
therefore it is not eligible for a reward at aklamio). You can either use
booleans (true = aklamio/false = others), or provide a text describing the
attribution channel (e.g. "Aklamio"/"Affiliate Network"/... ). We will only
consider sales for referrals, if the value is "true"/"Aklamio"/not provided
at all.
(string)
: The AID is a direct reference to the Aklamio 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. You can take
it from there dynamically and pass it on to the script. Note that AID takes
precedence over any other Aklamio tracking mechanism (coupon, cookies, etc.).
(string)
: 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.
(Object)
: 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.
(function (trackingAttribution: (string | boolean)): Request)
: Setter for trackingAttribution.
(function (): Promise)
: This function sends the request to Aklamio servers. You can check in your browser console the result of the 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.
/,<>?;:'”\|[{}]!@#$%^&*()=+`~
).
/,<>?;:'”\|[{}]!@#$%^&*()=+`~
).
Check the full Item object:
An Item object returned by com.aklamio.sales.createItem
Type: Object
(string)
: 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)
: 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
((number | ContractPricing))
: 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 setPrice(1400)
(string)
: 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
(string)
(number)
: Reward as a fixed value
(number)
: Reward as a percentage
(function (name: string): Item)
: Setter for name.
(function (price: (number | ContractPricing)): Item)
: Setter for price.
(function (category: string): Item)
: Setter for category.
(function (rewardCategory: string): Item)
: Setter for rewardCategory.
(function (rewardPercent: number): Item)
: Setter for rewardPercent. Note that rewardPercent and rewardFixed should not be set in the same item object.
(function (rewardFixed: number): Item)
: Setter for rewardFixed. Note that rewardPercent and rewardFixed should not be set in the same item object.
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
- As an Aklamio customer, you will receive a native cashback key in a secure way.
- Use that native cashback key to encrypt the users email address using one of the following code snippets:
-
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
Examples
Check the following complete examples to see how to use TrackingJS.