Technical documentation for understanding pixel installation.
Installation Overview
Place your unique Spotify main pixel script to collect views and visits. You will need to install the Main Pixel Script snippet in at least 3 pages. However, we recommend that you place the main pixel on every page of your website. The more website data, the more attribution data!
We also offer the option to include more advanced conversion events.
- Alias
- Lead
- Product
- Add to cart
- Check out
- Purchase
Pixel Installation
To measure the connection between podcast ad download and on-site web conversion, Spotify Ad Analytics provides an event logging JavaScript SDK. You only need to correctly set it up once to monitor conversions across any podcast using Spotify Ad Analytics.
In your Spotify Ad Analytics Dashboard navigate to Manage > Your Pixels to obtain your Pixel ID and install the following before the end body tag. Remember to replace 'Pixel ID' with your respective Pixel ID.
Main Pixel Script
The Main Pixel Script is required to start tracking activity on your website. You will need to install the Main Pixel Script snippet in at least 3 pages, however, we recommend that you place the main pixel on every page of your website. The more website data, the more attribution data!
<script>
// Installation script generated by Ad Analytics
(function(w, d){
var id='spdt-capture', n='script';
if (!d.getElementById(id)) {
w.spdt =
w.spdt ||
function() {
(w.spdt.q = w.spdt.q || []).push(arguments);
};
var e = d.createElement(n); e.id = id; e.async=1;
e.src = 'https://pixel.byspotify.com/ping.min.js';
var s = d.getElementsByTagName(n)[0];
s.parentNode.insertBefore(e, s);
}
w.spdt('conf', { key: 'Pixel ID' });
// Dynamically populate alias from session data
w.spdt('alias', { id: 'ConversionType' });
w.spdt('view');
})(window, document);
</script>
Conversion Event Pixel Scripts
Spotify Ad Analytics supports 6 different conversion events (click to jump to each):
- Alias
- Lead
- Product
- Add to cart
- Check out
- Purchase
You can install these conversion event pixel scripts after the main pixel script and on the page where you want to track these specific events.
Alias
Spotify Ad Analytics only provides data in an aggregated, anonymized format. An Alias event can be used to match Spotify Ad Analytics' internal cookie ID with your hashed internal user IDs.
Include your hashed internal ID within the "id" field within the alias event script and Spotify Ad Analytics will send encrypted data.
spdt('alias', {
id: 'hashed internal ID',});
Lead
A Lead event can be used to help you track when a user has completed an action, such as submitted a form, signed up for a free trial, clicked a button, etc.
The Lead event also has a value field that can be used to track revenue, if a specific value is entered. If a 0 or no value is entered, revenue will not be tracked.
Lead fields type and category can be used to track different types of lead events (e.g. newsletter signup vs request for a quote). The values for type and category can be any string and are optional.
spdt("lead", {
value: 50.00, // How much you value the lead.
currency: "USD"
// optional fields
type: "car",
category: "ford",});
The Product, Add to cart, Checkout and Purchase conversion events allow you to enter more detailed information for advanced analytics.
Product
A user viewed a product:
spdt("product", {
value: , // could be variant price or product price.
currency: "USD",
// optional product information for advanced analytics.
product_id: "",
product_name: "",
product_type: "",
product_vendor: "",});
Add to cart
A user added a product to the cart:
spdt('addtocart', {
value: 21.2, // price
currency: 'USD',
// optional product information for advanced analytics.
quantity: 2,
product_id: '',
product_name: '',
product_type: '',
product_vendor: '',
variant_id: '',
variant_name: '',});
Check out
A user initiated a checkout:
spdt('checkout', {
value: 10.0, // price
currency: 'USD',
discount_code: 'PODCAST_CODE',
// optional line_items, if you would like advanced analytics.
quantity: 3,
line_items: [
{
value: 21.2,
quantity: 1,
product_id: '',
product_name: '',
product_type: '',
product_vendor: '',
variant_id: '',
variant_name: '',
},
{
value: 42.4,
quantity: 2,
product_id: '',
product_name: '',
product_type: '',
product_vendor: '',
variant_id: '',
variant_name: '',
},
],});
Purchase
A user purchased products:
spdt('purchase', {
value: 10.0, // price
currency: 'USD',
discount_code: 'PODCAST_CODE',
// We will use this to match up everything in the backend.
order_id: '12322323232',
// is this a new purchase or a purchase from a returning customer?
is_new_customer: true,
//
// OPTIONAL quantity, line_items, if you would like advanced analytics.
//
quantity: 3,
line_items: [
{
value: 21.2,
quantity: 1,
product_id: '',
product_name: '',
product_type: '',
product_vendor: '',
variant_id: '',
variant_name: '',
},
{
value: 42.4,
quantity: 2,
product_id: '',
product_name: '',
product_type: '',
product_vendor: '',
variant_id: '',
variant_name: '',
},
],});
Content Security Policy
If you are using a Content Security Policy, you will need to add the following two lines:
script-src 'unsafe-inline' https://pixel.byspotify.com;
connect-src https://pixels.spotify.com;