Search.../

trackEvent( )

Sends a tracking event to external analytics tools.

Description

The trackEvent() function sends an event to analytics tools connected to your site. It can send events to Google Analytics and Facebook Pixel. To learn how to connect analytics tools to your site, see About Tracking Tools & Analytics.

The following events are available:

  • "AddProductImpression": When a user views a product. (Google Analytics only)
  • "ClickProduct": When a user clicks on a product. (Google Analytics only)
  • "ViewContent": When a key page is viewed.
  • "AddToCart": When a user adds a product to the shopping cart.
  • "RemoveFromCart": When a user removes a product from the shopping cart. (Google Analytics only)
  • "InitiateCheckout": When a user starts the checkout process.
  • "StartPayment": When a user starts the payment process. (Google Analytics only)
  • "AddPaymentInfo": When a user saves payment information.
  • "CheckoutStep": When a user completes a custom checkout step. (Google Analytics only)
  • "Purchase": When the checkout process is complete.
  • "Lead": When a user subscribes to a newsletter or submits a contact form.
  • "CustomEvent": When a user performs an event not listed above. The CustomEvent object contains one required property, event, and any number of custom properties. When sending a custom event to Google Analytics, include following parameters:
    • eventCategory: string: object that was interacted with
    • eventAction: string: type of interaction
    • eventLabel (optional): string: event category
    • eventValue (optional): integer: numeric value associated with the event

Note: The trackEvent() function only runs on published versions of your site. It does not work when previewing your site.

Syntax

function trackEvent(eventName: string, parameters: AddPaymentInfoEvent | AddProductImpressionEvent | AddToCartEvent | ClickProductEvent | CustomEvent | InitiateCheckoutEvent | PurchaseEvent | RemoveFromCartEvent | ViewContentEvent): void

trackEvent Parameters

NAME
TYPE
DESCRIPTION
eventName
string

The name of the event.

parameters
AddPaymentInfoEvent | AddProductImpressionEvent | AddToCartEvent | ClickProductEvent | CustomEvent | InitiateCheckoutEvent | PurchaseEvent | RemoveFromCartEvent | ViewContentEvent

The event's parameters.

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

Send a trackEvent with parameters

Code Example

Copy Code
1import wixWindow from 'wix-window';
2
3wixWindow.trackEvent("ViewContent", {
4 "origin": "My Sportswear Store",
5 "id": "P12345",
6 "name": "Really Fast Running Shoes",
7 "category": "Apparel/Shoes",
8 "price": 120,
9 "currency": "USD",
10 "brand": "SomeBrand",
11 "variant": "Black",
12 "position": 1
13} );
Send a trackEvent that doesn't take any parameters

Code Example

Copy Code
1import wixWindow from 'wix-window';
2
3wixWindow.trackEvent("Lead");
Send a trackEvent from the onReady event handler

Code Example

Copy Code
1import wixWindow from 'wix-window';
2
3$w.onReady(function () {
4 if(wixWindow.rendering.env === "browser") {
5 wixWindow.trackEvent("ViewContent", {
6 "origin": "My Sportswear Store",
7 "id": "P12345",
8 "name": "Really Fast Running Shoes",
9 "category": "Apparel/Shoes",
10 "price": 120,
11 "currency": "USD",
12 "brand": "SomeBrand",
13 "variant": "Black",
14 "position": 1
15 } );
16 }
17} );