Skip to content

WP Pixel Integration with Shopify

Warning

The plugin currently does not have active support.
In case of errors, we recommend integration via Google Tag Manager or manual insertion of the codes on the site.

Step 1: Paste the basic WP Pixel code

  1. Go to: Online StoreThemesActionsEdit code
  2. Then navigate to: layouttheme.liquid
  3. Just before closing the <head> section add:
<script>
    !function(w,p,e,v,n,t,s){w['WphTrackObject'] = n;
    w[n] = window[n] || function() {(w[n].queue=w[n].queue||[]).push(arguments)},
    w[n].l = 1 * new Date(), w[n].v = '2.0', t=p.createElement(e), s=p.getElementsByTagName(e)[0],
    t.async=1;t.src=v;s.parentNode.insertBefore(t,s)}(window,document,'script',
    'https://pixel.wp.pl/w/PIXEL_ID/tr.js', 'wph');
    wph('init', 'PIXEL_ID');
    wph('go');
</script>

Important!

Remember to replace the PIXEL_ID with your own Pixel ID!

The website administrator is responsible for properly embedding the WP Pixel tracking script, i.e., after the user has given consent.

The script should be embedded in its entirety, and calling the wph('go') function within it signifies the user's consent to tracking.

Withdrawing user consent should result in calling the wph('stop') function.


Step 2: Include the snippet at the bottom of <body>

  1. In the theme.liquid file, just before </body>, add:
{% include "wppixel.liquid" %}

Step 3: Create the snippet wppixel.liquid

  1. Go to: SnippetsAdd a new snippet
  2. Name it wppixel
  3. Paste the following code:
{%- if template %}
<script>
// View
  wph('track', 'ViewContent', { 'content_name': 'View' })
</script>
{% endif -%}

{%- if template == "collection" %}
<script>
// ProductList
    var contents = [];
{% for product in collection.all_products %}
  var item = {
    id: "{{ product.id}}",
    name:  "{{ product.title}}",
    category: "{{ product.type}}",
    price:  Number( ({{product.price}}/100).toFixed(2))
  }
  contents.push(item)
{% endfor %}
  wph('track', 'ViewContent', {
    'content_name': 'ProductList',
    contents: contents
  });
</script>

<script>
// AddToCart (for collection)
    var contents_c = [];
{% for product in collection.all_products %}
  var item = "{{ product.id}}"
  contents_c.push(item)
{% endfor %}
var buttons = document.getElementsByName('add');

buttons.forEach(function(button, index) {
    button.addEventListener('click', function() {
        var idp = buttons[index].getAttribute('id').split('--')[1];
        var i = contents_c.indexOf(idp);
        var c = contents[i];
        wph('track', 'AddToCart', {
            contents: [{
                id: c.id,
                name: c.name,
                category: c.category,
                price: c.price,
                quantity: 1
            }]
        });
    });
});
</script>
{% endif -%}

{%- if template == "product" %}
<script>
// ViewProduct
  wph('track', 'ViewContent', {
    'content_name': 'ViewProduct',
    contents: [{
      id: "{{product.id}}",
      name: "{{product.title}}",
      category: "{{product.type}}",
      price: Number(({{product.price}}/100).toFixed(2)),
      quantity: 1
    }]
  })
</script>

<script>
// AddToCart (for product)
window.addEventListener('DOMContentLoaded', function() {
var button = document.getElementsByName('add')[0];
button.addEventListener('click', function() {
    var cart_ids1 = [];
    var cart_q1 = []
{% for product in cart.items %}

  var id = "{{ product.id}}"
  var quantity = {{product.quantity}}

  cart_ids1.push(id)
  cart_q1.push(quantity)
{% endfor %}
wph('track', 'AddToCart', {
      contents: [{
      id: "{{product.id}}",
      name: "{{product.title}}",
      category: "{{product.type}}",
      price: Number(({{product.price}}/100).toFixed(2))
      }]
  });
}, false);
});
</script>
{% endif -%}

Step 4: Add the purchase event (Purchase)

  1. Go to: SettingsCheckoutAdditional Scripts
  2. Paste the following code:
<script>
    !function(w,p,e,v,n,t,s){w['WphTrackObject'] = n;
    w[n] = window[n] || function() {(w[n].queue=w[n].queue||[]).push(arguments)},
    w[n].l = 1 * new Date(), w[n].v = '2.0', t=p.createElement(e), s=p.getElementsByTagName(e)[0],
    t.async=1;t.src=v;s.parentNode.insertBefore(t,s)}(window,document,'script',
    'https://pixel.wp.pl/w/PIXEL_ID/tr.js', 'wph');
    wph('init', 'PIXEL_ID');
    wph('go');
</script>

<script>
var coupons = [];
{% for discount in order.discounts %}
var c = "{{ discount.code }}"
coupons.push(c)
{% endfor %}
if(coupons[0] == ""){
var coupon = undefined} else {
var coupon = coupons[0]
}
var contents = [];
{% for product in line_items %}
var item = {
id: '{{product.product.id}}',
name: '{{product.product.title}}',
category: '{{product.product.type}}',
price: Number(({{product.price}}/100).toFixed(2)),
quantity: {{product.quantity}}
}
contents.push(item)
{% endfor %}
wph('track', 'Purchase', {
transaction_id: '{{ order_number }}',
value: Number((({{ total_price }}-{{tax_price}}* ({{ total_price }}-{{ shipping_price }})/{{ total_price }} -{{ shipping_price }})/100).toFixed(2)),
value_gross: Number((({{ total_price }}-{{ shipping_price }})/100).toFixed(2)),
shipping_cost: Number(({{ shipping_price }}/100).toFixed(2)),
discount_code: coupon,
contents: contents
});
</script>

Done!

WP Pixel integration has been successfully completed 🎉
If you encounter technical difficulties, you can use integration via GTM or ask your developer for support.


Warning

The Plugin is provided “AS IS”, WITHOUT ANY WARRANTIES, either express or implied, including but not limited to implied warranties of merchantability, fitness for a particular purpose, proper functioning, compatibility with external platforms (such as Shopify, WooCommerce, PrestaShop, or other e-commerce systems), or compatibility with other plugins. Wirtualna Polska Media S.A. does not warrant that the Plugin will be error-free, operate without interruption, or meet the User’s expectations.

TO THE MAXIMUM EXTENT PERMITTED BY LAW, WIRTUALNA POLSKA MEDIA S.A. DISCLAIMS ALL LIABILITY for any damages arising from the use of or inability to use the Plugin, including indirect, consequential, or incidental damages, loss of profits, data, or business interruption, regardless of the legal basis of the claim.

Wirtualna Polska Media S.A. may, but is not obligated to, update the Plugin. The company shall not be liable for any issues resulting from updates, changes to APIs or infrastructures of external platforms (e.g., Shopify, WooCommerce, PrestaShop, or other e-commerce systems), or interactions with other software. The User is responsible for testing the Plugin before production use and bears sole responsibility for maintaining compatibility within their environment. By using the Plugin, the User accepts these terms and assumes all risks associated with its use.

The above provisions do not exclude liability for damages caused intentionally by Wirtualna Polska Media S.A., nor in any cases where such exclusion would be contrary to mandatory provisions of law.