AppmakerDeveloper

How to add an analytics event

Track your own analytics events with analytics.track from @appmaker-xyz/core.

  1. Import the analytics
import { analytics } from "@appmaker-xyz/core";
  1. Add the following code to the place where you want to track the event
analytics.track(
  "event_name",
  {
    // event properties  (optional)
  },
  {
    // event context  (optional)
  }
);

Example:

analytics.track(
  "discount_banner_click",
  {
    discount_percentage: "50 %",
  },
  {
    cart: {
      total: 100,
      currency: "EUR",
      lineItems: [
        {
          name: "Product 1",
          quantity: 1,
          price: 50,
          currency: "EUR",
        },
        {
          name: "Product 2",
          quantity: 1,
          price: 50,
          currency: "EUR",
        },
      ]
    },
    // other context properties
  }
);