Skip to main content
Custom Sales data script

Add and adapt a script to your site that sends sales data to you account

Updated this week

Introduction

PriceShape provides an open API to integrate sales data from your shop, allowing you to track conversion rates, set up price strategies based on product performance, and create intelligent product groupings based on sales data.

The data can be sent to PriceShape via the Sales data API or with PriceShape's Sales data script.

Notes on Implementation

  • The script is designed for use in the website’s source code.

  • If you choose to use a tag manager, you must adapt the script to your setup.

Overview of Data Events

The following events can be tracked and sent to PriceShape for each product:

  1. Page Views: The total number of product-specific pages viewed.

  2. Products Added to Cart: The number of times a product is added to the shopping cart.

  3. Products Sold: The total quantity of a specific product sold.

  4. Unique Product Sales: The number of unique transactions involving a specific product.

Client-side script

The Script works by events or triggers, this means that when a customer navigates or interferes with a certain part of the website, the scrips needs to be triggered accordingly.

Head script

Place in the <head> tag of your page template. The script <head> script should be available on all pages on you website or at a minimum pages where we need to track sales data, furthermore it needs to be located above the event scripts in the source code.

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

<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>

Event scripts

Implement in the bottom of the <body> element for all pages to track page events.

Product page views:

Trigger condition: Whenever 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 all variants clicked.

// 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 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 card

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

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

All data must be in JSON format and follow these naming conventions:

  • pageViews

  • upi (See PriceShape UPI here)

  • itemsSold

  • uniqueSales

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:

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

Ensure that:

  • Strings and numbers are appropriately distinguished.

Did this answer your question?