Sending ecommerce commands

Reminder: To associate a web user’s visit with their potential purchases (and corresponding revenue), you need to send the transaction information to Contentsquare using a dedicated command. This command will send Contentsquare the order reference, its amount, bought items, etc.

Sending a transaction (without Merchandising)

Section titled Sending a transaction (without Merchandising)

To send transaction information to Contentsquare, execute the following command each time a visitor to your website completes a purchase (and populate the values below accordingly for the ID, the revenue and the currency)

<script type="text/javascript">
window._uxa = window._uxa || [];
// Push transaction info into CS global object
window._uxa.push(['ec:transaction:create', {
'id': '123', /* Transaction ID (string, up to 40 characters) */
'revenue': '9.99', /* Transaction's total amount paid (integer or string, up to 12 digits and 2 decimals - extra decimals are truncated) */
'currency': 'usd' /* Currency value (string - numeric or alphanumeric ISO 4217 value) (optional) */
}]);
</script>

Followed by:

<script type="text/javascript">
// Send the information to Contentsquare
window._uxa.push(['ec:transaction:send']);
</script>

Assuming no additional merchandising information needs to be sent, you could include the ec:transaction:send command inside the same <script> tag:

<script type="text/javascript">
window._uxa = window._uxa || [];
// Push transaction info into CS global object
window._uxa.push(['ec:transaction:create', {
'id': '123', /* Transaction ID (string, up to 40 characters) */
'revenue': '9.99', /* Transaction's total amount paid (integer or string, up to 12 digits and 2 decimals - extra decimals are truncated) */
'currency': 'usd' /* Currency value (string - numeric or alphanumeric ISO 4217 value) (optional) */
}]);
// Send the information to Contentsquare
window._uxa.push(['ec:transaction:send']);
</script>

You can send several transactions to Contentsquare but with different IDs:

  • If multiple transactions are sent with an identical transaction ID on the same session, only the last one received is inserted in the database,
  • If multiple transactions are sent with different transaction IDs (even on the same session), all of them will be on the database.

Sending a transaction (for Merchandising)

Section titled Sending a transaction (for Merchandising)

When implementing the ecommerce tracking for our Merchandising product, you would be required to specify what products were purchased in each transaction, in addition to the regular transactional information already mentioned above.

For each product purchased, the following script should be triggered, in addition to the generic transaction information explained above, followed by the command ec:transaction:send:

<script type="text/javascript">
// Push individual product info into CS global object
window._uxa.push(['ec:transaction:items:add', {
'id': '123', /* Transaction ID (string, up to 40 characters) */
'sku': '123ABC', /* Product code (string, up to 20 characters) */
'price': '9.99', /* Product unit price actually paid by the visitor; Not the nominal price (integer or string, up to 6 digits and 2 decimals - extra decimals are truncated) */
'quantity': '1', /* Quantity (whole number between 1 and 32766) */
'name': 'Black scarf', /* Product name (string, up to 50 characters) */
'category': 'Scarves', /* optional - Product category (string, up to 20 characters) */
}]);
</script>

Thus, the code for a full transaction for Merchandising should look something like below:

<script type="text/javascript">
window._uxa = window._uxa || [];
// Push transaction info into CS global object
window._uxa.push(['ec:transaction:create', {
'id': '123', /* Transaction ID (string, up to 40 characters) */
'revenue': '9.99', /* Transaction's total amount paid (integer or string, up to 12 digits and 2 decimals - extra decimals are truncated) */
'currency': 'usd' /* Currency value (string - numeric or alphanumeric ISO 4217 value) (optional) */
}]);
// Push individual product info into CS global object (to be repeated per each product)
window._uxa.push(['ec:transaction:items:add', {
'id': '123', /* Transaction ID (string, up to 40 characters) */
'sku': '123ABC', /* Product code (string, up to 20 characters) */
'price': '9.99', /* Product unit price actually paid by the visitor; Not the nominal price (integer or string, up to 6 digits and 2 decimals - extra decimals are truncated) */
'quantity': '1', /* Quantity (whole number between 1 and 32766) */
'name': 'Black scarf', /* Product name (string, up to 50 characters) */
'category': 'Scarves', /* optional - Product category (string, up to 20 characters) */
}]);
// Send the information to Contentsquare
window._uxa.push(['ec:transaction:send']);
</script>

Here is an example of a complete transaction (including individual products for Merchandising) with transactional information taken from the datalayer:

<script type="text/javascript">
window._uxa = window._uxa || [];
window._uxa.push(['ec:transaction:create', {
'id': dataLayer.ecommerce.transactionId,
'revenue': dataLayer.ecommerce.totalRevenue,
'currency': dataLayer.ecommerce.currency
}]);
for (var i=0; i<dataLayer.ecommerceItems.length; i++) {
window._uxa.push(['ec:transaction:items:add', {
'id': dataLayer.ecommerce.transactionId,
'name': dataLayer.ecommerceItems[i].name,
'sku': dataLayer.ecommerceItems[i].sku,
'category': dataLayer.ecommerceItems[i].category,
'price': dataLayer.ecommerceItems[i].finalPrice,
'quantity': dataLayer.ecommerceItems[i].quantity
}]);
}
window._uxa.push(['ec:transaction:send']);
</script>

Orders or products without any amount

Section titled Orders or products without any amount

Every order must have an amount. To pass those transactions anyway in your conversion rate, you can add an amount of 0; anyhow, be careful of the consequences on the average cart (the same goes for the pricing of a cart product).

Verifying the sending of transactions

Section titled Verifying the sending of transactions

Our Contentsquare Tracking Setup Assistant Chrome Extension will display each transaction sent with its parameters.

To check the actual data sent for transactions, follow GET requests to //c.contentsquare.net/transaction, with the following parameters:

parameterdefinitiontype
pidproject IDInteger
idtransaction identifierString
revenueorder amountDouble
items (optional)order’s products listJSON