Skip to content

Conversation

@mariana-caetano
Copy link
Contributor

@mariana-caetano mariana-caetano commented Nov 10, 2025

Types of changes

  • New content (guides, endpoints, app documentation)
  • Improvement (make a documentation even better)
  • Fix (fix a documentation error)
  • Spelling and grammar accuracy (self-explanatory)

Release note: https://vtex-dev.atlassian.net/browse/EDU-16613

@mariana-caetano mariana-caetano self-assigned this Nov 10, 2025
@github-actions
Copy link
Contributor

Navigation Preview Link

No changes detected in the navigation.json file

@github-actions
Copy link
Contributor

Grammar review summary

Review for docs/faststore/docs/sdk/analytics/send-analytics-event.mdx

The document has several minor grammatical and stylistic issues, primarily related to hyphenation of 'e-commerce', sentence structure, and consistency in terminology. Corrections improve clarity, conciseness, and adherence to common technical writing conventions.

Review for docs/faststore/docs/sdk/analytics/sending-custom-events.mdx

The document has several minor grammatical and stylistic issues, primarily related to hyphenation of 'e-commerce' and 'non-e-commerce', phrasing for clarity and conciseness, and consistent use of articles. Corrections have been suggested to improve formality and readability.


Was this feedback useful?

  • Yes
  • No

@github-actions
Copy link
Contributor

Preview Links

Open this URL to set up the portal with this branch changes.

You can now access the edited pages with the following URLs:

@github-actions
Copy link
Contributor

Grammar review summary

Review for docs/faststore/docs/sdk/analytics/send-analytics-event.mdx

The document is generally well-written. Minor improvements include removing a redundant word, enhancing clarity in a usage description, and addressing a contraction and a phrasing for better formality and precision.

Review for docs/faststore/docs/sdk/analytics/sending-custom-events.mdx

The document contains several grammar and style issues, including inconsistent hyphenation for 'e-commerce' terms, use of contractions, and minor phrasing improvements for clarity and formality. Corrections have been provided to enhance readability and adhere to standard technical writing guidelines.


Was this feedback useful?

  • Yes
  • No

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions
Copy link
Contributor

Grammar review summary

Review for docs/faststore/docs/sdk/analytics/send-analytics-event.mdx

The review identified three issues: one instance of redundancy in the introductory text, one paragraph that could be rephrased for better clarity and flow in the 'Usage' section, and one instance of a contraction and unclear phrasing in a JSDoc comment.

Review for docs/faststore/docs/sdk/analytics/sending-custom-events.mdx

The document has several instances of 'ecommerce' which should be 'e-commerce' for consistency with Google Analytics terminology. There are also minor phrasing improvements for clarity and conciseness, and a missing emoji colon in an info callout.


Was this feedback useful?

  • Yes
  • No

@github-actions
Copy link
Contributor

github-actions bot commented Nov 10, 2025

Documentation feedback for docs/faststore/docs/sdk/analytics/sending-custom-events.mdx

General Feedback

The guide provides a good overview of how to send custom events in FastStore using sendAnalyticsEvent and useAnalyticsEvent. However, it lacks a clear introductory paragraph stating the goal of the guide. The structure is generally good, but the step titles are not in imperative form, and the guide could benefit from a "Before you begin" section to list any prerequisites.

Actionable Feedback

  1. Frontmatter: Add createdAt and slug to the frontmatter.
  2. Introduction: Add a goal-oriented introductory paragraph explaining what the reader will accomplish by following the guide.
  3. Before you begin: Add a "Before you begin" section listing any prerequisites.
  4. Step Titles: Rewrite the step titles to follow the "Step N - Imperative title" format.
  5. Code Formatting: Ensure consistent code formatting throughout the guide.
  6. Consistency: Maintain consistency in the use of terminology (e.g., "event interface" vs. "event type").
  7. Next Steps: Consider adding a "Next steps" section to suggest related tasks or further reading.

Suggested Revision

---
title: "Sending custom events"
slug: "sending-custom-events"
excerpt: "Learn how to define and send custom events in FastStore using the sendAnalyticsEvent and useAnalyticsEvent functions."
createdAt: "2024-01-01T00:00:00Z"
---

Even though the [Analytics](https://developers.vtex.com/docs/guides/faststore/analytics-overview) module natively supports [Google Analytics ecommerce events](https://support.google.com/analytics/answer/14434488?hl=en), you may need to track customer activity not covered by default events. In such cases, you can trigger and intercept custom events using the [`sendAnalyticsEvent`](https://developers.vtex.com/docs/guides/faststore/analytics-send-analytics-event) and [`useAnalyticsEvent`](https://developers.vtex.com/docs/guides/faststore/analytics-use-analytics-event) functions. In this guide, you will learn how to define and send custom events to track customer activity beyond the default events provided by the Analytics module.

> ℹ️ For a practical example of sending custom events, see the [Implementing custom newsletter analytics events](https://developers.vtex.com/docs/guides/faststore/analytics-implementing-custom-newsletter-analytics-events) guide.

## Before you begin

Before you start, make sure you have:

*   A FastStore project set up.
*   Familiarity with TypeScript and React.
*   The `@faststore/sdk` package installed.

## Instructions

### Step 1 - Declare an interface for your custom event

To trigger a custom event, you must define an interface that describes the structure of your event object, including its properties and types. There are three approaches to doing this:

- [Creating a new event interface](#creating-a-new-event-interface)
- [Extending existing types from the Analytics Module](#extending-existing-types-from-the-analytics-module)
- [Overriding Multiple Types](#overriding-multiple-types)

#### Creating a new event interface

To create a custom event interface, use the `sendAnalyticsEvent` function. This function requires the event to include the following properties:

| Property name | Type | Description | Default |
| ------------------- |-------- |---------------- |---------|
| `name`            | `string` | The name of the event that appears in Analytics reports. The `name` does not need to follow any event name conventions related to natively supported events. | Required |
| `params` | `any` | Any type and value for your custom event. | Required |
| `isEcommerceEvent` | `boolean` | When `true`, wraps `params` in an `ecommerce` object following the GA4 ecommerce data model. When `false`, sends `params` at the top level for [custom non-ecommerce events](https://support.google.com/analytics/answer/14240153?hl=en). | `true` |

In the following example, we define a custom event called `WishlistEvent` to track when a user adds a product to their wishlist. Since this is not a standard ecommerce event, we set `isEcommerceEvent: false`:

```ts
import { sendAnalyticsEvent } from '@faststore/sdk'

interface WishlistEvent {
    name: 'wishlist_event'
    isEcommerceEvent: false
    params: {
        productId: string
        productName: string
        userId: string
        isLoggedIn: boolean
    }
}

sendAnalyticsEvent<WishlistEvent>({
    name: 'wishlist_event',
    isEcommerceEvent: false,
    params: {
        productId: '12345',
        productName: 'Example Product',
        userId: 'user-abc',
        isLoggedIn: true
    }
})
```

This custom event interface captures when a user adds a product to their wishlist, logging details like `productId`, `productName`, and whether the user is logged in (`isLoggedIn`). By setting `isEcommerceEvent: false`, the parameters are sent at the top level of the event payload, following the [Google Analytics 4 format for custom events](https://support.google.com/analytics/answer/14240153?hl=en).

#### Extending existing types from the Analytics module

If your event is related to an existing one, you can extend relevant types from the Analytics module. You can do this by using the [TypeScript's generics](https://www.typescriptlang.org/docs/handbook/2/generics.html) with the [`sendAnalyticsEvent`](https://developers.vtex.com/docs/guides/faststore/analytics-send-analytics-event) function.

The following example extends the `AddToCartEvent` interface to include the `couponCode` property, which is useful for tracking if a customer applied a coupon code when adding an item to the cart:

```ts
import type { AddToCartEvent } from '@faststore/sdk'
import { sendAnalyticsEvent } from '@faststore/sdk'

interface AddToCartExtended extends AddToCartEvent {
    couponCode: string
}

/* ... */

sendAnalyticsEvent<AddToCartExtended>({ name, params, couponCode })
```

#### Overriding multiple types

If you have multiple custom events, such as adding/removing items from the cart or viewing products, you can define a unified type to handle them all. This approach simplifies firing multiple events from the same interface.

```ts
/* types.ts */
import { sendAnalyticsEvent } from '@faststore/sdk'

type AddToCartExtended = /* ... */
type RemoveFromCartExtended = /* ... */
type ViewItemExtended = /* ... */
type SelectItemExtended = /* ... */

type ExtendedEvents =
| AddToCartExtended
| RemoveFromCartExtended
| ViewItemExtended
| SelectItemExtended

type SendExtendedAnalyticsEvent = (event: ExtendedEvents) => void

export const sendExtendedAnalyticsEvent: SendExtendedAnalyticsEvent = (event) =>
sendAnalyticsEvent<ExtendedEvents>(event)
```

```ts
/* MyComponent.tsx */
import { sendExtendedAnalyticsEvent } from './types'

/* ... */

sendExtendedAnalyticsEvent({ /* Extended event object */})
```

The example above sets up a flexible way to fire multiple custom events. Instead of managing multiple event types separately, the purpose of the example is to handle them all through a single interface. You can use this setup to track diverse customer interactions, such as adding/removing products from the cart, viewing products, or saving items to the wishlist.

### Step 2 - Intercept custom events

After defining the event interface, you'll need to intercept these events using the `useAnalyticsEvent` hook. Below is an example of how to set up an event handler:

```ts
import { useAnalyticsEvent } from '@faststore/sdk'

import type { ArbitraryEvent } from './types'

export const AnalyticsHandler = () => {
    useAnalyticsEvent((event: ArbitraryEvent) => {
    })

    /* ... */

    return null
}
```

Note that to target extended properties of events, you'll also need to configure the types of your [`useAnalyticsEvent`](https://developers.vtex.com/docs/guides/faststore/analytics-use-analytics-event) callback function to expect an event of that type.

```ts
import { useAnalyticsEvent } from '@faststore/sdk'

import type { ExtendedEvents } from './types'

export const AnalyticsHandler = () => {

    useAnalyticsEvent((event: ExtendedEvents) => {
        /* ... */
    })

    /* ... */

    return null
}
```

>ℹ️ By typing the callback function with the extended types, you can reference properties not natively provided by the Analytics module.

### Step 3 - Fire custom events

Now that you have declared your event interface and intercepted it with the `useAnalyticsEvent` hook, you can implement it in your components to fire the event.

```ts
import { useCallback } from 'react'
import { sendAnalyticsEvent } from '@faststore/sdk'

const MyComponent = () => {
    const handleCustomEvent = useCallback(() => {
        sendAnalyticsEvent({
            name: 'custom_action',
            isEcommerceEvent: false,
            params: {
                action_type: 'button_click',
                component_name: 'MyComponent',
                timestamp: new Date().toISOString()
            }
        })
    }, [])

    return <button onClick={handleCustomEvent}>Trigger Custom Event</button>
}
```

> ℹ️ Use `isEcommerceEvent: false` for custom events that track user interactions, feature usage, or other non-commerce activities. Reserve the default `isEcommerceEvent: true` (or omit it) for events related to the shopping funnel (add to cart, purchase, etc.).

## Next steps

*   Explore the [Analytics Overview](https://developers.vtex.com/docs/guides/faststore/analytics-overview) guide for more information on the Analytics module.
*   Refer to the [Implementing custom newsletter analytics events](https://developers.vtex.com/docs/guides/faststore/analytics-implementing-custom-newsletter-analytics-events) guide for a practical example.
*   Consult the documentation for [`sendAnalyticsEvent`](https://developers.vtex.com/docs/guides/faststore/analytics-send-analytics-event) and [`useAnalyticsEvent`](https://developers.vtex.com/docs/guides/faststore/analytics-use-analytics-event) for advanced usage.

Was this feedback useful?

  • Yes
  • No

@github-actions
Copy link
Contributor

Grammar review summary

Review for docs/faststore/docs/sdk/analytics/send-analytics-event.mdx

The document is well-written and clear. Only a minor formatting and terminology consistency improvement was identified in a JSDoc comment.

Review for docs/faststore/docs/sdk/analytics/sending-custom-events.mdx

The document is generally well-written but has minor grammatical and stylistic inconsistencies, primarily related to hyphenation of compound adjectives (e.g., 'e-commerce', 'event-naming'), possessive forms, and phrasing for clarity in technical contexts. Typographic consistency for the info icon was also addressed.


Was this feedback useful?

  • Yes
  • No

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions
Copy link
Contributor

Grammar review summary

Review for docs/faststore/docs/sdk/analytics/send-analytics-event.mdx

The document is well-written with only one minor issue identified regarding terminology in a comment. The suggested changes improve precision and consistency in technical language.

Review for docs/faststore/docs/sdk/analytics/sending-custom-events.mdx

The document has several instances where 'ecommerce' should be hyphenated as 'e-commerce' for consistency and clarity. A few sentences were rephrased for better flow and formality, and a period was added to a table description. The possessive apostrophe was removed from 'TypeScript's generics' for common technical usage.


Was this feedback useful?

  • Yes
  • No

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions
Copy link
Contributor

Grammar review summary

Review for docs/faststore/docs/sdk/analytics/send-analytics-event.mdx

The document is well-written with only one minor suggestion for conciseness in technical writing.

Review for docs/faststore/docs/sdk/analytics/sending-custom-events.mdx

The document is well-written and clear. The identified issues are minor stylistic improvements focused on conciseness and precision, enhancing overall readability and technical accuracy.


Was this feedback useful?

  • Yes
  • No

## Usage

In the component related to the event, declare a callback function. In this function, define an event object with the desired event type (example: `add_to_cart`) and call `sendAnalyticsEvent`. Then, pass the related event as an argument. Finally, call the callback function in the event trigger (example: `onClick`).
In the event-related component, define a callback function that creates an event object with the desired type (for example, `add_to_cart`) and calls `sendAnalyticsEvent`, passing the event as an argument. Then, trigger the callback function in the corresponding event handler (such as `onClick`).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [Grammar reviewer] reported by reviewdog 🐶
Using 'e.g.,' (exempli gratia) is more concise and commonly used in technical documentation than 'for example,'.

Suggested change
In the event-related component, define a callback function that creates an event object with the desired type (for example, `add_to_cart`) and calls `sendAnalyticsEvent`, passing the event as an argument. Then, trigger the callback function in the corresponding event handler (such as `onClick`).
In the event-related component, define a callback function that creates an event object with the desired type (e.g., `add_to_cart`) and calls `sendAnalyticsEvent`, passing the event as an argument. Then, trigger the callback function in the corresponding event handler (such as `onClick`).

| `params` | `any` | Any type and value your custom event uses. |
| Property name | Type | Description | Default |
| ------------------- |-------- |---------------- |---------|
| `name` | `string` | The name of the event that appears in Analytics reports. The `name` does not need to follow any event name conventions related to natively supported events. | Required |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [Grammar reviewer] reported by reviewdog 🐶
Replacing 'related to' with 'for' makes the sentence more concise and direct, improving readability.

Suggested change
| `name` | `string` | The name of the event that appears in Analytics reports. The `name` does not need to follow any event name conventions related to natively supported events. | Required |
| `name` | `string` | The name of the event that appears in Analytics reports. The `name` does not need to follow any event name conventions for natively supported events. | Required |


#### Extending existing types from the Analytics module

If your event is related to an existing one, you can extend relevant types from the Analytics module. You can do this by using the [TypeScript generics](https://www.typescriptlang.org/docs/handbook/2/generics.html) with the [`sendAnalyticsEvent`](https://developers.vtex.com/docs/guides/faststore/analytics-send-analytics-event) function.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [Grammar reviewer] reported by reviewdog 🐶
Adding an apostrophe-s ('s) to 'TypeScript' clarifies possession and makes the phrase 'TypeScript's generics' sound more natural when referring to a feature of the language.

Suggested change
If your event is related to an existing one, you can extend relevant types from the Analytics module. You can do this by using the [TypeScript generics](https://www.typescriptlang.org/docs/handbook/2/generics.html) with the [`sendAnalyticsEvent`](https://developers.vtex.com/docs/guides/faststore/analytics-send-analytics-event) function.
If your event is related to an existing one, you can extend relevant types from the Analytics module. You can do this by using TypeScript's generics with the [`sendAnalyticsEvent`](https://developers.vtex.com/docs/guides/faststore/analytics-send-analytics-event) function.

```

Note that to target extended properties of events, you'll also need to configure the types of your [`useAnalyticsEvent`](https://developers.vtex.com/docs/guides/faststore/analytics-use-analytics-event) callback function to expect an event of such type.
Note that to target extended properties of events, you'll also need to configure the types of your [`useAnalyticsEvent`](https://developers.vtex.com/docs/guides/faststore/analytics-use-analytics-event) callback function to expect an event of that type.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [Grammar reviewer] reported by reviewdog 🐶
The verb 'access' is more precise than 'target' in the context of working with properties of an object, improving clarity.

Suggested change
Note that to target extended properties of events, you'll also need to configure the types of your [`useAnalyticsEvent`](https://developers.vtex.com/docs/guides/faststore/analytics-use-analytics-event) callback function to expect an event of that type.
Note that to access extended properties of events, you'll also need to configure the types of your [`useAnalyticsEvent`](https://developers.vtex.com/docs/guides/faststore/analytics-use-analytics-event) callback function to expect an event of that type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [Grammar reviewer] reported by reviewdog 🐶
Rephrasing to 'it aims to handle' makes the sentence more concise and less clunky, improving flow and readability.

The example above sets up a flexible way to fire multiple custom events. Instead of managing multiple event types separately, the purpose of the example is to handle them all through a single interface. You can use this setup to track diverse customer interactions, such as adding/removing products from the cart, viewing products, or saving items to the wishlist.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [Grammar reviewer] reported by reviewdog 🐶
Clarifying 'it' as 'this functionality' makes the sentence more precise and less ambiguous, improving clarity.

Now that you have declared your event interface and intercepted it with the `useAnalyticsEvent` hook, you can implement it in your components to fire the event.

Copy link
Collaborator

@carolinamenezes carolinamenezes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Achei um pouco misturado o que deveria ser referência e guia de implementação

| `params` | `object` | Event-specific parameters and data. | Required |
| `isEcommerceEvent` | `boolean` | Determines event structure. When `true`, wraps `params` in an `ecommerce` object following the GA4 ecommerce data model. When `false`, sends `params` at the top level for custom non-ecommerce events. | `true` |

### Using custom events without ecommerce structure
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Using custom events without ecommerce structure
### `isEcommerceEvent`

}
```

#### Example: Ecommerce event (default behavior)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#### Example: Ecommerce event (default behavior)
#### GA4 ecommerce event (`isEcommerceEvent: true`)

```

#### Example: Ecommerce event (default behavior)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Use `isEcommerceEvent: true` (default) to format the event according to the GA4 ecommerce data model, wrapping all parameters inside the ecommerce object. Take the following example


By default, `sendAnalyticsEvent` wraps event parameters in an `ecommerce` object to follow the [Google Analytics 4 ecommerce events](https://support.google.com/analytics/answer/14434488?hl=en) structure. However, for custom events that don't represent ecommerce actions, you should set `isEcommerceEvent: false` to send parameters at the top level, following the [GA4 custom events format](https://support.google.com/analytics/answer/14240153?hl=en).

#### Example: Custom event with `isEcommerceEvent: false`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#### Example: Custom event with `isEcommerceEvent: false`
#### Custom events without GA4 `ecommerce` (`isEcommerceEvent: false`)

}
```

## Exporting custom event types with generics
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Exporting custom event types with generics
## Typed custom events

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Só faz sentido para isCommerce: false?
Caso positivo, mover para a categoria correspondente

Comment on lines +21 to +27
To create a custom event interface, use the `sendAnalyticsEvent` function. This function requires the event to include the following properties:

| Property name | Type | Description |
| ------------------- |-------- |---------------- |
| `name` | `string` | The name of the event that appears in Analytics reports. The `name` doesn't need to follow any event name conventions related to natively supported events. |
| `params` | `any` | Any type and value your custom event uses. |
| Property name | Type | Description | Default |
| ------------------- |-------- |---------------- |---------|
| `name` | `string` | The name of the event that appears in Analytics reports. The `name` does not need to follow any event name conventions related to natively supported events. | Required |
| `params` | `any` | Any type and value for your custom event. | Required |
| `isEcommerceEvent` | `boolean` | When `true`, wraps `params` in an `ecommerce` object following the GA4 ecommerce data model. When `false`, sends `params` at the top level for [custom non-ecommerce events](https://support.google.com/analytics/answer/14240153?hl=en). | `true` |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Não precisa repetir tudo. Só utilizar o link da doc de referência e explicar que, nessa doc, é usado isEcommerceEvent: false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants