Developer Guide
API GuideDeveloper Guide
  • Overview
    • Getting Started
    • Customers and Visitors
    • Events and Business Objects (BOs)
      • Sample Event Templates
  • Website
    • Getting Started
      • Direct JS Implementation
      • JS Integration via GTM
      • Tracking Haravan website events
    • Tracking Users
    • Tracking Events
      • [Direct] Sample E-Commerce Events
        • View Product
        • Add a Product to the Shopping Cart
        • View the Shopping Cart
        • Remove a Product from the Shopping Cart
        • Search for Product(s)
        • Checkout Shopping Cart
        • Apply Promotion Code
        • Purchase Product(s)
      • [GTM] Sample E-Commerce Events
        • View Product
        • Add a Product to the Shopping Cart
        • View the Shopping Cart
        • Remove a Product from the Shopping Cart
        • Search for Product(s)
        • Checkout Shopping Cart
        • Apply Promotion Code
        • Purchase Product(s)
    • Web Push
  • Android
    • Getting Started
    • Tracking Users
    • Tracking Events
    • Push Messaging
    • App Inbox Messaging
  • iOS
    • Getting Started
      • Integration of Antsomi iOS SDK
    • Tracking Users
    • Tracking Events
    • Push Messaging
  • Hybrid Apps
    • React Native
      • Tracking Users
      • Tracking Events
        • Sample E-Commerce Events
          • View Product
          • Add a Product to the Shopping Cart
          • View the Shopping Cart
          • Remove a Product from the Shopping Cart
          • Search for Product(s)
          • Checkout Shopping Cart
          • Apply Promotion Code
          • Purchase Product(s)
      • Push Messaging
      • App Inbox Messaging
    • Flutter
      • Tracking Users
      • Tracking Events
        • Sample E-Commerce Events
          • View Product
          • Add a Product to the Shopping Cart
          • View the Shopping Cart
          • Remove a Product from the Shopping Cart
          • Search for Product(s)
          • Checkout Shopping Cart
          • Purchase Product(s)
      • Push Messaging
      • App Inbox Messaging
      • App In-line Content
  • Antsomi Service Integrations
    • Media Template
    • Media JSON
      • Sample E-Commerce Events
        • Search for Product(s)
        • View Product
        • Add a Product to the Shopping Cart
        • Checkout Shopping Cart
        • Purchase Product(s)
      • Sample User Events
        • Sign-in
        • Sign-up
      • Sample Opt-in Events
        • Subscribe to Email marketing
        • Subscribe to OneSignal channel
  • 3rd Party Integrations
    • Shopify
      • Tracking Shopify website events
    • LINE
      • Integrating LINE Login with your web app
    • Google Ad Manager
      • Targeting CDP365 segment via PPID(s)
Powered by GitBook
On this page
  • Tracking StoreFront
  • Tracking Checkout Event
  • Script pubsub function
  • Insert the script into the file
  1. 3rd Party Integrations
  2. Shopify

Tracking Shopify website events

This guide provides a detailed walkthrough for tracking CDP events on your Shopify website

PreviousShopifyNextLINE

Last updated 1 year ago

Tracking StoreFront

Download the file cdp-tracking-script.liquid and put it in the folder Snippets:

Tracking Checkout Event

Step by step go to Order status page setting: Home > scroll end page > click button Go to checkout setting > Order status page

Download the file cdp-order-status.liquid and Insert it into the Order Status page:

Script pubsub function

Download the file cdp-pubsub.js and put it in the folder Assets:

Insert the script into the file

1. Script get cart

Insert the script below into the file theme.liquid (If the theme hasn't returned the JSON data within the cart yet).

<script id="cart-json">
  var xhr = new XMLHttpRequest();
  xhr.open('GET', 'https://shopify.antsomi.com/cart.json', true);

  xhr.onload = function () {
    if (xhr.status >= 200 && xhr.status < 300) {
      var response = JSON.parse(xhr.responseText);
      document.getElementById('cart-json').textContent = JSON.stringify(response, null, 2);
    }
    else {
      console.error('Request failed:', xhr.status, xhr.statusText);
    }
  };
  xhr.onerror = function () {
    console.error('Connection error');
  };
  xhr.send();
</script>

2. Event Remove Cart

Go to the file Assets/cart.js and call the publish() function in the CartRemoveButton class.

class CartRemoveButton extends HTMLElement {
  constructor() {
    super();
    this.addEventListener('click', (event) => {
      event.preventDefault();
      this.closest('cart-items').updateQuantity(this.dataset.index, 0);
      let indexItem = this.dataset.index;
      let e = { 
        data : {
          index : +indexItem
        }
      };
      publish("antsomi:removeCart", e); //Call the 'publish' function in the CartRemoveButton class
    });
  }
}

3. Event Sign-In

Go to the file customers/login.liquid in the folder Templates.

Insert the script at the end of the page:

<script>
  let btnLogin = document.querySelector('#customer_login button');
  btnLogin.addEventListener('click', function(){
    sessionStorage.setItem('loginSubmitted', 1);
  })
</script>

4. Event Sign-up

Go to the file customers/request.liquid in the folder Templates.

Insert the script at the end of the page:

<script>
  let btnLogin = document.querySelector('#create_customer button');
  btnLogin.addEventListener('click', function(){
    sessionStorage.setItem('registerSubmitted', 1);
  })
</script>
link
link
link