AppmakerDeveloper

How to add custom properties to CleverTap purchase recordPurchase function

Add custom properties to the CleverTap purchase event with the clevertap-record-purchase-event-params filter.

Steps

  1. Import appmaker from @appmaker-xyz/core
import { appmaker } from "@appmaker-xyz/core";
  1. Add filter to modify the params in your theme activate function
appmaker.addFilter(
  'clevertap-record-purchase-event-params',
  'custom-events',
  ({ recordEventCheckoutData, recordEventCheckoutLineItems, cart }) => {
    console.log(cart);
    console.log(recordEventCheckoutData);
    console.log(recordEventCheckoutLineItems);
    recordEventCheckoutData = {
      ...recordEventCheckoutData,
      some_custom_property: 'some_custom_value', // from cart object you will get all the details
    };
    // edit recordEventCheckoutLineItems with every item object add additonal properties
    recordEventCheckoutLineItems = recordEventCheckoutLineItems.map((item) => {
      item = {
        ...item,
        some_custom_property: 'some_custom_value', // from cart object you will get all the details
      };
      return item;
    });

    return {
      recordEventCheckoutData,
      recordEventCheckoutLineItems,
    };
  },
);

Current Default Event data


recordEventCheckoutData

  {
    "transaction_id": "order name",
    "total_value": 823
  }

recordEventCheckoutLineItems

  [
    {
      "product_id": 1234,
      "brand": "My Brand",
      "product_name": "My Product Name",
      "variant_id": 55678,
      "quantity": 1,
      "price": 256,
      "variant_name": "Yellow"
    },
    {
      "product_id": 4567,
      "brand": "My Brand",
      "product_name": "My Product Name",
      "variant_id": 67890,
      "quantity": 2,
      "price": 567,
      "variant_name": "Black"
    }
  ]

cart

Please refer to the Shopify documentation for the cart object data https://shopify.dev/docs/api/storefront/latest/objects/Cart