> ## Documentation Index
> Fetch the complete documentation index at: https://docs.paraminternationalltd.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Custom Events

> Custom events help you track actions specific to your website, such as registrations, purchases, subscriptions, and feature usage.

Before tracking custom events, make sure the Twinalyze SDK is initialized.

## Track an event

Use the `track()` method and pass the event name as the first parameter.Pass an object as the second parameter to send additional information with the event.

<CodeGroup>
  ```javascript npm theme={null}
  TwinalyzeAnalytics.track("productViewed", 
   { //Add event propteries according to your needs
    productId: "PROD_101",
    productName: "Nike Air Running Shoes",
    productCategory: "Footwear",
    brand: "Nike",
    variant: "Black / UK 9",
    price: 3499,
    currency: "INR",
  })
  ```

  ```javascript CDN theme={null}
  window.TwinalyzeAnalytics.track("signUp",
   { //Add event propteries according to your needs
    productId: "PROD_101",
    productName: "Nike Air Running Shoes",
    productCategory: "Footwear",
    brand: "Nike",
    variant: "Black / UK 9",
    price: 3499,
    currency: "INR",
  })
  ```
</CodeGroup>

## Parameters

| Parameter    | Type   | Required | Description                                  |
| ------------ | ------ | -------- | -------------------------------------------- |
| `eventName`  | String | Yes      | Name of the custom event.                    |
| `properties` | Object | No       | Additional information related to the event. |

## Examples

### Track product viewed

<CodeGroup>
  ```javascript npm theme={null}
  TwinalyzeAnalytics.track("productViewed", {
    productId: "PROD_101",
    productName: "Nike Air Running Shoes",
    productCategory: "Footwear",
    brand: "Nike",
    variant: "Black / UK 9",
    price: 3499,
    currency: "INR",
  });
  ```

  ```javascript CDN theme={null}
  window.TwinalyzeAnalytics.track("productViewed", {
    productId: "PROD_101",
    productName: "Nike Air Running Shoes",
    productCategory: "Footwear",
    brand: "Nike",
    variant: "Black / UK 9",
    price: 3499,
    currency: "INR",
  });
  ```
</CodeGroup>

### Track add to cart

<CodeGroup>
  ```javascript npm theme={null}
  TwinalyzeAnalytics.track("productAddedToCart", {
    productId: "PROD_101",
    productName: "Nike Air Running Shoes",
    productCategory: "Footwear",
    brand: "Nike",
    variant: "Black / UK 9",
    quantity: 1,
    price: 3499,
    totalAmount: 3499,
    currency: "INR",
  });
  ```

  ```javascript CDN theme={null}
  window.TwinalyzeAnalytics.track("productAddedToCart", {
    productId: "PROD_101",
    productName: "Nike Air Running Shoes",
    productCategory: "Footwear",
    brand: "Nike",
    variant: "Black / UK 9",
    quantity: 1,
    price: 3499,
    totalAmount: 3499,
    currency: "INR",
  });
  ```
</CodeGroup>

### Track a purchase

<CodeGroup>
  ```javascript npm theme={null}
  TwinalyzeAnalytics.track("checkoutStarted", {
    cartId: "CART_501",
    itemCount: 2,
    subtotal: 4498,
    discountAmount: 500,
    shippingAmount: 99,
    totalAmount: 4097,
    currency: "INR",
    couponCode: "WELCOME500",
    items: [
      {
        productId: "PROD_101",
        productName: "Nike Air Running Shoes",
        variant: "Black / UK 9",
        quantity: 1,
        price: 3499,
      },
      {
        productId: "PROD_102",
        productName: "Sports Ankle Socks",
        variant: "White",
        quantity: 1,
        price: 999,
      },
    ],
  });
  ```

  ```javascript CDN theme={null}
  window.TwinalyzeAnalytics.track("checkoutStarted", {
    cartId: "CART_501",
    itemCount: 2,
    subtotal: 4498,
    discountAmount: 500,
    shippingAmount: 99,
    totalAmount: 4097,
    currency: "INR",
    couponCode: "WELCOME500",
    items: [
      {
        productId: "PROD_101",
        productName: "Nike Air Running Shoes",
        variant: "Black / UK 9",
        quantity: 1,
        price: 3499,
      },
      {
        productId: "PROD_102",
        productName: "Sports Ankle Socks",
        variant: "White",
        quantity: 1,
        price: 999,
      },
    ],
  });
  ```
</CodeGroup>

## Recommended naming

Use clear and consistent event names that describe the completed user action.

<CodeGroup>
  ```javascript npm theme={null}
  TwinalyzeAnalytics.track("checkoutStarted");
  TwinalyzeAnalytics.track("reportExported");
  TwinalyzeAnalytics.track("checkoutCompleted");
  TwinalyzeAnalytics.track("paymentFailed");
  TwinalyzeAnalytics.track("subscriptionPurchased");
  TwinalyzeAnalytics.track("subscriptionCancelled");
  ```

  ```javascript CDN theme={null}
  window.TwinalyzeAnalytics.track("checkoutStarted");
  window.TwinalyzeAnalytics.track("reportExported");
  window.TwinalyzeAnalytics.track("checkoutCompleted");
  window.TwinalyzeAnalytics.track("paymentFailed");
  window.TwinalyzeAnalytics.track("subscriptionPurchased");
  window.TwinalyzeAnalytics.track("subscriptionCancelled");
  ```
</CodeGroup>

<div className="twinalyze-bottom-nav">
  <a href="/sdks/javascript/analytics/identify-user" className="twinalyze-nav-side">
    <span className="twinalyze-nav-arrow">‹</span>
    <span>Previous</span>
  </a>

  <a href="/sdks/javascript/analytics/auto-event-tracking" className="twinalyze-nav-center">
    <strong>Automatic event tracking</strong>
    <span>Automatically track common website interactions.</span>
  </a>

  <a href="/sdks/javascript/analytics/auto-event-tracking" className="twinalyze-nav-side">
    <span>Next</span>
    <span className="twinalyze-nav-arrow">›</span>
  </a>
</div>
