Track Analytics Events

You can track analytics events in your Wix-managed headless project using the @wix/site package. Use trackEvent() to send standard and custom events from your headless site. Events are sent to the Wix analytics infrastructure and can be forwarded to connected external platforms such as Google Analytics (GA4), Facebook Pixel, or Google Tag Manager.

Notes:

  • Analytics tracking is available with Wix's Astro integration only. The scripts that deliver events are injected when Wix builds your project, which doesn't happen for projects built with another web framework.
  • These scripts run under a site's current default consent policy. On a newly created managed headless site, that policy grants every category until a visitor chooses otherwise. If a site needs opt-in consent, such as under GDPR, see Manage Cookie Consent to restrict the policy before these scripts run.

To track analytics events in a headless site:

  1. Install the @wix/site package.
  2. Track standard events.
  3. Optionally, track custom events.
  4. Connect external analytics platforms (optional).
  5. Deploy a site.

Prerequisites

  • A Wix-managed headless project built with Astro. See Quick Start with the CLI.
  • A custom domain connected to a site. Analytics events are only delivered on sites with a custom domain.

Step 1 | Install the @wix/site package

Run the following command in your project directory:

Copy

Then import the analytics module in any file where you want to track events:

Copy

Note: With Wix's Astro integration, the CLI handles authentication automatically. You don't need to create a Wix client or configure OAuth. Just import and call SDK methods directly.

Step 2 | Track standard events

Use trackEvent() to send standard analytics events. These events are recognized by external analytics platforms like Google Analytics and Facebook Pixel.

The following standard events are supported:

Event NameDescription
AddPaymentInfoVisitor saves payment information.
AddProductImpressionVisitor views a product.
AddToCartVisitor adds a product to the cart.
CheckoutStepVisitor completes a checkout step.
ClickProductVisitor clicks on a product.
CompleteRegistrationVisitor completes registration.
InitiateCheckoutVisitor starts the checkout process.
LeadVisitor submits a form or subscribes to a newsletter.
PurchaseCustomer completes a purchase.
RemoveFromCartVisitor removes a product from the cart.
ScheduleVisitor schedules a meeting or appointment.
StartPaymentVisitor starts the payment process.
ViewContentVisitor views a key page, such as a product page.

For a full reference of event properties, see About Analytics Events.

Examples

Track a product view:

Copy

Track a completed purchase:

Copy

Step 3 | Track custom events (optional)

You can also track custom events for business-specific actions not covered by the standard event types. Pass "CustomEvent" as the event name and include your custom data in the event data object:

Copy

Custom events are forwarded to connected analytics platforms along with the data you provide.

Step 4 | Connect external analytics platforms (optional)

To forward tracked events to an external analytics platform, connect one or more of the following from the site dashboard:

Once connected, events sent with trackEvent() are forwarded to the platform automatically.

Step 5 | Deploy a site

Analytics events are only sent to the Wix analytics infrastructure on a deployed site. The analytics scripts that handle event delivery are injected during the production build.

To build and deploy a site:

Copy

Note: During local development with wix dev, trackEvent() calls execute without errors, but events aren't delivered to the analytics backend. To verify that events are being tracked, deploy a site and check the Wix dashboard analytics or connected external platform.

See also

Last updated: 12 August 2026

Did this help?