Transmitting basket data via
...
server side Webhooks
Before you start
If you implement your own Webhook in the UI you will find you can use various placeholders to transmit conversion related data from the platform to your own system. However, a placeholder related to basket data is not among them. This is because basket data consists of several data elements, which cannot be transmitted via one placeholder. If you follow the instructions below however, you can make sure basket data is transmitted all the same. Please note the solution with javascript is highly recommended, only use the solution with the image code if you do not have another option.
Transmitting basket data via an image code
Suppose the image pixel you have implemented is the followingwant to transfer Basket data via server side Webhooks, you have two options:
Use the
#{BASKET}
parameter to have the whole basket transferred as a single URL-encoded JSON string. This is easier to implement, but usually requires more effort on the receiving end.If you cannot use option 1, then you have the option to access parts of the baskets and send them as ordered lists.
Sending JSON via the #{BASKET} parameter
Let’s say you have the following Target URL configured in your Target Configuration:
Code Block |
---|
yourcode.tracking.org/aff_l?channel_id=234&adv_sub?basket=#{CONVERSION_ID}&amount=#{ORDER_VALUE} |
When you want to transmit basket data, you first need to create a parameter, for example pid=
. This parameter needs to be filled with a placeholder called #{BASKET_VALUE_trc}
. When you have added this placeholder, your code will look more or less like this:
Code Block |
---|
yourcode.tracking.org/aff_l?channel_id=234&adv_sub=#{CONVERSION_ID}&amount=#{ORDER_VALUE}&pid=#{BASKET_VALUE_trc} |
...
BASKET} |
After the system computed a conversion, it will call the generated target URL:
Code Block |
---|
yourcode.tracking.org&basket=%5B%7B%22pid%22%3A%226553%22%2C%22prn%22%3A%22Shoe%22%2C%22brn%22%3A%22Jordan%22%2C%22pri%22%3A%2250.00%22%2C%22qty%22%3A%221%22%2C%22trc%22%3A%22default%22%2C%22prc%22%3A%22shoes%22%7D%2C%7B%22pid%22%3A%2212355%22%2C%22prn%22%3A%22Shirt%22%2C%22brn%22%3A%22Addidas%22%2C%22pri%22%3A%2270.00%22%2C%22qty%22%3A%222%22%2C%22trc%22%3A%22default%22%2C%22prc%22%3A%22shirts%22%7D%5D |
Beautiful, isn’t it? The given basket is, as mentioned, a URL-encoded string. When encoded (and formatted for readability) it will look like this:
Code Block | ||
---|---|---|
| ||
[{
"pid": "6553",
"prn": "Shoe",
"brn": "Jordan",
"pri": "50.00",
"qty": "1",
"trc": "default",
"prc": "shoes"
}, {
"pid": "12355",
"prn": "Shirt",
"brn": "Addidas",
"pri": "70.00",
"qty": "2",
"trc": "default",
"prc": "shirts"
}] |
That’s it!
Sending the basket as lists via the #{BASKET_ARRAY} parameters
If, for some reason, you cannot compute JSON on the receiving end, you have the option of sending the basket elements as lists.
The key elements to this method are the two parameters #{BASKET_ARRAY_BEGIN}
at the beginning and and #{BASKET_ARRAY_END}
at the end of the code. When you have added these placeholders, your code will look more or less like this:
...
. These work in conjunction, and the actual basket parameters you want to receive have to be placed between the two.
The following Parameters are used to declare basket values:
BASKET_VALUE_pid, BASKET_VALUE_qty, BASKET_VALUE_pri, BASKET_VALUE_pri_cents, BASKET_VALUE_prn
Let’s look at a simple example:
Let’s say you have the following Target URL configured in your Target Configuration:
Code Block | ||
---|---|---|
| ||
yourcode.tracking.org/aff_l?channel_id=234&adv_sub=#{CONVERSION_ID}&amount=#{ORDER_VALUE}&pid=?basket=#{BASKET_ARRAY_BEGIN}#{BASKET_VALUE_trcpid}#{BASKET_ARRAY_END} |
As soon as you have created this code, all you need to do is implement it following the instructions in the article on the Webhooks feature.
Transmitting basket data via javascript
Suppose the javascript you have implemented is the following:
Code Block |
---|
<script type="text/javascript">
document.write('<img src="http://yourcode.tracking.org/aff_l?channel_id=234&adv_sub=#{CONVERSION_ID}&amount=#{ORDER_VALUE}" width="1" height="1" border="0" />');
</script> |
To make sure the code transmits basket data, you need to start by adding a a parameter, for example pid=
. This parameter needs to be filled with a placeholder called #{BASKET_VALUE_trc}
. When you have added this placeholder, your code will look more or less like this:
Code Block |
---|
<script type="text/javascript">
document.write('<img src="http://yourcode.tracking.org/aff_l?channel_id=234&adv_sub=#{CONVERSION_ID}&amount=#{ORDER_VALUE}&pid=#{BASKET_VALUE_trc}" width="1" height="1" border="0" />');
</script> |
To make sure the basket data is transmitted in one string, you need to add to more placeholders: #{BASKET_ARRAY_BEGIN}
at the beginning and #{BASKET_ARRAY_END}
at the end of the code. When you have added these placeholders, your code will look more or less like this:
...
Given a conversion with the following basket:
Code Block | ||
---|---|---|
| ||
[{
"pid": "6553",
"prn": "Shoe",
"brn": "Jordan",
"pri": "50.00",
"qty": "1",
"trc": "default",
"prc": "shoes"
}, {
"pid": "12355",
"prn": "Shirt",
"brn": "Addidas",
"pri": "70.00",
"qty": "2",
"trc": "default",
"prc": "shirts"
}] |
The system would generate the following URL:
Code Block | ||
---|---|---|
| ||
yourcode.tracking.org?basket=6553%2C12355 |
Again, URL decoded it would look like this:
Code Block | ||
---|---|---|
| ||
yourcode.tracking.org?basket=6553,12355 |
You can also define a separator (currently available options are ,;|
) on your #{BASKET_ARRAY_BEGIN}
declaration:
Code Block | ||
---|---|---|
| ||
yourcode.tracking.org?basket=#{BASKET_ARRAY_BEGIN separator='|'}#{BASKET_VALUE_pid}#{BASKET_ARRAY_END} |
Would generate (skipping the URL-decode part)
Code Block | ||
---|---|---|
| ||
yourcode.tracking.org?basket=6553|12355 |
Now let us look at two more complex examples that show you ways to transfer baskets to your system.
Code Block | ||
---|---|---|
| ||
yourcode.tracking.org?pid=#{BASKET_ARRAY_BEGIN separator='|'}#{BASKET_VALUE_pid}#{BASKET_ARRAY_END}&qty=#{BASKET_ARRAY_BEGIN separator=';'}#{BASKET_VALUE_pri}#{BASKET_ARRAY_END}&pri_cents=#{BASKET_ARRAY_BEGIN separator=';'}#{BASKET_VALUE_pri_cents}#{BASKET_ARRAY_END}&prn=#{BASKET_ARRAY_BEGIN}#{BASKET_VALUE_prn}#{BASKET_ARRAY_END} |
Would generate:
Code Block | ||
---|---|---|
| ||
yourcode.tracking.org?pid=6553|12355&qty=1,2&pri_cents=5000;3500&prn=Shoe|Shirt |
As soon as you have created this code, all you need to do is implement it following the instructions in the article on the Webhooks feature.
...