FastStore
FastStore SDK
Analytics
The Analytics module manages events on a website. The module is composed of two main functions:
sendAnalyticsEvent
: Fires events in the browser. Events fired using this function are shared only with the website's origin. The event is wrapped and sent to the Window object via standardpostMessage
calls.useAnalyticsEvent
: Intercepts fired events and usually communicates with an analytics provider.
Events sent via the Analytics module are not automatically sent to any analytics provider (e.g., Google Analytics). To connect with a provider, configure theuseAnalyticsEvent
hook.
The Analytics module supports sending and receiving different events, allowing you to implement custom event types and override default ones.
Additionally, the Analytics module offers built-in ecommerce event types based on the Google Analytics 4 (GA4) data model.
List of native event types
The Analytics module comes with native types based on ecommerce events. All event types are available for use and extension. Here is a list of events natively supported by the Analytics module:
Type | Parameters |
---|---|
add_payment_info | currency , value , coupon , payment_type , and items |
add_shipping_info | currency , value , coupon , shipping_tier , and items |
add_to_cart | currency , value , and items |
add_to_wishlist | currency , value , and items |
begin_checkout | currency , value , coupon , and items |
login | method |
page_view | page_title , page_location , and send_page_view |
purchase | currency , transaction_id , value , affiliation , coupon , shipping , tax , and items |
refund | currency , transaction_id , value , affiliation , coupon , shipping , tax , and items |
remove_from_cart | currency , value , and items |
search | search_term |
select_item | item_list_id , item_list_name , and items |
select_promotion | item_list_id , item_list_name , and items |
share | method , content_type , and item_id |
signup | method , content_type , and item_id |
view_cart | currency , value , and items |
view_item | currency , value , and items |
view_item_list | item_list_id , item_list_name , and items |
view_promotion | items |
Each event exports at least two types: one for the event parameters and one for the event type itself. For example, the
add_to_cart
event has two exported types: AddToCartParams<T extends Item = Item>
and AddToCartEvent<T extends Item = Item>
.Some types are common to all events, such as the
Item
type. These types are particularly useful when overriding Item
properties or a whole Item
itself.Google Analytics 4
Google Analytics is the industry-leading analytics solution that most ecommerce websites use, and the Analytics module was designed with this in mind. All the helper functions and hooks in the module use the Google Analytics 4 (GA4) data model by default. This allows you to use code hinting tools to receive suggestions of GA4 events and their recommended properties while coding.
To send the events to Google Analytics, use the
useAnalyticsEvent
hook. The hook must listen to events from sendAnalyticsEvents
and add them to the dataLayer
(recommended for Google Tag Manager) or call the gtag
function directly (for gtag
script implementations).Code hinting
By leveraging the type definitions in the Analytics module, you can use IntelliSense suggestions for code hinting.