Implementing Amazon.com Conversion Pixel

Some merchants choose to advertise their products on Amazon.com.  To gauge the effectiveness of the advertising, a conversion pixel needs to be deployed onto the receipt.  At this point in time UltraCart does not have built in support for this particular pixel, but this tutorial will walk you through how to deploy in the conversion HTML section.

First let's take a look at the pixel code that is provided by Amazon.

Sample Conversion Pixel Code
<!-- Use of this pixel is subject to the Amazon ad specs and policies at https://sellercentral.amazon.com/gp/help/201622840 -->
<script type="text/javascript">
/*
In order to obtain full conversion reporting, you must configure and add
this code to your website. Whenever a shopper purchases items from your
website, you should render this code snippet into their browser with
details about the items were purchased. Instructions on how to configure
this code are inlined as comments in the code.
*/

/*
The _paPixel array stores information about purchases. You will push
arrays containing purchase details onto it. The first element in each
array determines the type of information being provided - it is a string
designating the name of the field.
*/
var _paPixel = _paPixel || [];

/*
These fields are already properly filled. They are necessary and should
NOT be modified.
*/
_paPixel.push(['merchantId', 'ABCDEFGHIJKLMN']);
_paPixel.push(['type', 'purchase']);
_paPixel.push(['uniqueEventId', (new Date()).getTime() + Math.random().toString(16).slice(2) ]);

/*
For each type of item purchased, you should push an array of purchase
details onto _paPixel. The first element of each array should be 'items',
and you should provide the following, respectively:

- SKU of the item on Amazon (this should be a JS String)
- quantity of the item purchased (this should be a JS Number)
- price of the item purchased (unit price) (this should be a JS String)
- currency used to purchase the item (this should be a JS String)

For example, an output string should look like (order matters):

_paPixel.push(['items', 'your-product-sku-1', 10, '39.99', 'USD']);

In the following code, replace '${itemsVar}' with the variable containing
an array of purchased items. Each item in the array is assumed to be an
object with SKU, quantity, price, and curency as properties. Then remove
the comments around the code to enable full conversion reporting:
*/
/*
items.forEach(function(item) {
_paPixel.push(['items', item.SKU, item.quantity, item.price, item.currency]);
});
*/

_paPixel.push(['submit']);

(function() {
var paPixel = document.createElement('script'); paPixel.type = 'text/javascript'; paPixel.async = true;
paPixel.src = '//d10so77biaxg0k.cloudfront.net/pa_pixel.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(paPixel, s);
})();
</script>

First we need to change this code to use Velocity calls to provide the information we're looking for.  We'll also remove all the extra comment code that doesn't need to be sent down to the browser.

Sample Conversion Pixel Code
<!-- Use of this pixel is subject to the Amazon ad specs and policies at https://sellercentral.amazon.com/gp/help/201622840 -->
<script type="text/javascript">
/*
The _paPixel array stores information about purchases. You will push
arrays containing purchase details onto it. The first element in each
array determines the type of information being provided - it is a string
designating the name of the field.
*/
var _paPixel = _paPixel || [];
_paPixel.push(['merchantId', 'ABCDEFGHIJKLMN']); /* CHANGE THIS TO YOUR AMAZON MERCHANT ID */
_paPixel.push(['type', 'purchase']);
_paPixel.push(['uniqueEventId', '${order.orderId}' ]);

/*
For each type of item purchased, you should push an array of purchase
details onto _paPixel. The first element of each array should be 'items',
and you should provide the following, respectively:

- SKU of the item on Amazon (this should be a JS String)
- quantity of the item purchased (this should be a JS Number)
- price of the item purchased (unit price) (this should be a JS String)
- currency used to purchase the item (this should be a JS String)

For example, an output string should look like (order matters):

_paPixel.push(['items', 'your-product-sku-1', 10, '39.99', 'USD']);

*/

#foreach($item in $order.items)
  _paPixel.push(['items', '${item.itemId}', $item.quantity, '${formatHelper.formatMoney($item.unitCostWithSubtotalDiscount)}', 'USD']);
#end ##foreach item

_paPixel.push(['submit']);

(function() {
var paPixel = document.createElement('script'); paPixel.type = 'text/javascript'; paPixel.async = true;
paPixel.src = '//d10so77biaxg0k.cloudfront.net/pa_pixel.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(paPixel, s);
})();
</script>

To deploy this code let's click on the Conversion Tracking tab of StoreFronts.

Now click on the "Custom" tab.

Paste in the code into the Conversion HTML field.  Make sure you notice the line highlighted in the screenshot below where you need to enter your own Amazon merchant ID.

Place a test order and make sure that the pixel fired properly on your receipt. Â