Personyze Wiki Personyze Wiki docs
Open Personyze
Docs/ Integrations/ Integrating Personyze Tracking with Shopify’s New Cart Extension
Integrations

Integrating Personyze Tracking with Shopify’s New Cart Extension

This guide explains how to use Personyze's JavaScript tracking code to monitor e-commerce events through Shopify's new cart extension. The code below tracks key customer interactions, including product views, cart additions and removals, and…

2 min read Updated 5 days ago
Using the Personyze Shopify app? You may not need this. The app embeds the tracking code in your theme for you and syncs your product catalog automatically — see Install Personyze on a Shopify store. The code below is for reporting events from Shopify’s Customer Events sandbox (checkout and the cart extension), which runs separately from your theme, or for stores that are not using the app.

This guide explains how to use Personyze’s JavaScript tracking code to monitor e-commerce events through Shopify’s new cart extension. The code below tracks key customer interactions, including product views, cart additions and removals, and completed purchases.

Step-by-Step Integration

Step 1: Initialize Personyze JavaScript SDK

Add this initialization script to your Shopify store’s theme code:

<script>
window._S_T || function(s)
{
  s.async = true;
  s.src = '//counter.personyze.com/stat-track-lib.js';
  s.onload = function()
  {
    _S_T.async = true;
    _S_T.setup({PERSONYZE-ACCOUNT ID, "*.yourdomain.com"}); // replace with your actual details
  };
  (document.querySelector('head') || document.documentElement).appendChild(s);
}(document.createElement('script'));
</script>

Important: Replace PERSONYZE-ACCOUNT ID with your actual Personyze account ID, and *.yourdomain.com with your actual domain.

Example:

_S_T.setup({123456, "*.examplestore.com"});

Step 2: Subscribe to Shopify Events for E-commerce Tracking

Add the following event subscription scripts to track key interactions:

<script>
analytics.subscribe("product_viewed", event => {
  if (event?.data?.productVariant) {
    console.log("Event data", event.data);
    (self.personyze=self.personyze||[]).push(['Product Viewed', event.data.productVariant.id]);
  }
});

analytics.subscribe("product_added_to_cart", event => {
  if (event?.data?.cartLine) {
    console.log("Event data", event.data);
    (self.personyze=self.personyze||[]).push(['Product Added to cart', event.data.cartLine.merchandise.id, 'quantity', event.data.cartLine.quantity]);
  }
});

analytics.subscribe("product_removed_from_cart", event => {
  console.log("Event data", event.data);
  (self.personyze=self.personyze||[]).push(['Product Removed from cart', event.data.cartLine.merchandise.id, 'quantity', event.data.cartLine.quantity]);
});

analytics.subscribe("checkout_completed", event => {
  console.log("Event data", event.data);
  (self.personyze=self.personyze||[]).push(['Products Purchased']);
});
</script>

Implementation Tips

  • Always test the integration thoroughly after implementation.
  • Check the browser console for “Event data” logs to verify that tracking events are correctly triggered.

By following these steps, Personyze will accurately track customer interactions with your Shopify cart extension, providing valuable data to enhance your store’s personalization and optimization strategies.

Did this page answer your question?
Thank you — that goes to whoever maintains this page.