Skip to main content

Custom sales data script

Add and adapt a script to your website to send sales and performance data to your PriceShape account.

Written by Sarah Fogtmand

PriceShape's Sales Data Script allows you to collect sales and performance data directly from your website and send it to PriceShape.

By sending data such as page views, products added to cart, and sales, you can bring your sales performance together with your product and pricing data in PriceShape. This gives you greater insight into how your products are performing and how pricing may relate to their performance.

You can use sales data to track metrics such as conversion rate, revenue, and sales performance, and to analyze products or set price strategies based on product performance.


Ways to send sales data with a custom integration

PriceShape provides two options for sending sales data through a custom integration:

  • Sales Data API: Build your own integration and send sales and performance data directly from your system to PriceShape.

  • PriceShape Sales Data Script: Add and adapt PriceShape's client-side script to your website to track events as they happen.

This article explains how to implement the Sales Data Script.


Before you start

The Sales Data Script requires implementation in your website's source code and should be adapted to your website and checkout setup.

Before implementing the script, make sure that:

  • You can add the script to the relevant pages of your website.

  • You know which UPI (Unique Product Identifier) is used for your products in PriceShape.

  • The UPI passed by the script corresponds to the product's UPI in PriceShape.

  • You know where and when the relevant events occur on your website, such as a product page being viewed, a product being added to the cart, or an order being completed.

Correct product identification is important because the UPI is used to connect the incoming sales data to the correct product in PriceShape.


Using a tag manager

The script is designed for implementation in your website's source code.

If you choose to implement it through a tag manager, you are responsible for adapting the script to your setup and configuring the appropriate triggers.

The triggers should fire when the corresponding event actually occurs, for example:

  • A product page is viewed.

  • A product is added to the cart.

  • A purchase is successfully completed.


What data can be sent?

For each product, you can track and send the following events:

  • Page views (pageViews): The number of times the product page has been viewed.

  • Products added to cart (itemAddedToCart): The number of times the product has been added to the cart.

  • Items sold (itemsSold): The total quantity of units sold.

  • Unique product sales (uniqueSales): The number of individual sales/transactions containing the product.

For example, if one order contains 3 units of the same product, this would normally represent:

  • itemsSold: 3

  • uniqueSales: 1


How the Sales Data Script works

The script is event-based. This means that your website needs to call the relevant PriceShape function when a specific customer action occurs.

For example:

Customer opens a product page
→ Trigger trackPage

Customer adds a product to the cart
→ Trigger itemAddedToCart

Customer completes a purchase
→ Trigger itemSold or itemsSold

The UPI sent with each event tells PriceShape which product the event belongs to.


Client-side script

Step 1 – Add the Head Script

Place the following script in the <head> of your page template.

The script should be available on all pages where you want to track events and must be loaded before any of the event scripts described below.

You can find your unique script in "Account settings" -> "Integrations".

It looks like this:

<script type="text/javascript"> (function (window) { function sendEvent(body) { if (!window.navigator || !window.navigator.sendBeacon) { console.log("This browser does not support sendBeacon"); return false;
} window.navigator.sendBeacon( "https://public.app.priceshape.io/api/2022-08/sales-data?app_id=####", JSON.stringify(body) );
} window.PRICESHAPE = { trackPage: function (upi) { sendEvent([
{ pageViews: 1, upi
}
]);
}, itemSold: function (upi, quantity = 1) { sendEvent([
{ itemsSold: quantity, uniqueSales: 1, upi
}
]);
}, itemsSold: function (data) { sendEvent(data);
}, itemAddedToCart: function (upi) { sendEvent([
{ itemAddedToCart: 1, upi
}
]);
},
};
})(window); </script>

Replace UPI with your UPI value for your integration.


Step 2 – Add the event scripts

Implement these at the bottom of the <body> on the relevant pages to track page events.

Product page views

Trigger condition: When a customer navigates to a product-specific URL.

If you work with variants, you might need to tweak the logic to account for variants by either:

  • Trigger a single view for the first variant clicked.

  • Trigger a view for each variant the customer clicks.

// Track a page view, by UPI
<script
type="text/javascript"> window.PRICESHAPE.trackPage(upi)
</script>


Items sold and unique sales:

Trigger condition: Once a customer purchases an item.

  • Items sold and unique sales should trigger on the “Thank you for your order page or when the transaction is completed.

// Track items sold, by UPI

<script
type="text/javascript"> window.PRICESHAPE.itemSold(upi, quantity) </script>

// if multiple products at once
// UPI is a string

window.PRICESHAPE.itemsSold([
{ upi: '001234567', itemsSold: 2, uniqueSales: 1},
{ upi: '000567789', itemsSold: 1, uniqueSales: 1},
])


Added to cart:

Triggers condition: Once a customer adds an item to the cart.

// Track added to cart, by UPI
<script
type="text/javascript"> window.PRICESHAPE.itemAddedToCart(upi)
</script>

Timestamp

Events can include an optional timestamp field.

The timestamp must use ISO-8601 format in UTC.

For example:

2023-04-10T02:12:00Z


Data format

Data should be submitted via a POST request to:

https://public.app.priceshape.io/api/2022-08/sales-data?app_id=xxxxxxxx

You can find your unique script in "Account settings" -> "Integrations".

Naming conventions and format

Data must be sent in JSON format using the supported field names:

  • pageViews

  • upi (See PriceShape UPI here)

  • itemsSold

  • uniqueSales

  • timestamp (ISO-8601 UTC)

The upi must correspond to the UPI used by the product in PriceShape.


Syntax example

Data requests should be posted as an array of objects.

Example:

[{"pageViews": 1, "upi": "5705145043275"},{ "upi": "5705145043275", "itemsSold": 2, "uniqueSales": 1},{"upi": "5705145043275", "itemAddedToCart": 2}]

For single events:

A single event should still be sent inside an array.

[{"upi": "5705145043275", "itemAddedToCart": 2}]

Note: Ensure that strings and numbers are appropriately distinguished.

The following fields must be sent as numbers, not strings:

pageViews

itemAddedToCart

itemsSold

uniqueSales

For example:

Correct:

"itemsSold": 4

Incorrect:

"itemsSold": "4"

Sending numeric values as strings can cause the data to not be processed correctly.

Did this answer your question?