How to set up Analytics for FTW
This guide describes how to set up analytics for Flex Template for Web (FTW).
Table of Contents
FTW supports tracking page views with pluggable analytics handlers.
Google Analytics (GA) is supported by default. To enable GA, set the GA
tracker ID to the environment variable
Note that the current script expects a Universal Analytics property only tracking ID. If you want to use GA4, you should update the Google Analytics scripts first.
That's it! You're good to go.
Note: Google Analytics doesn't work in hot-loading environment!
GA script is added in server-side setup. You can test it local environment with
yarn run dev-server.
If you want to add a new analytics library, you can do as follows:
To track page views, create a custom handler e.g. in
The handler should be a class that implements a
Note that the
url parameter might not be the same as in the URL bar of
the browser. It is the canonical form of the URL. For example, in the
listing page it doesn't have the dynamic title slug in the middle. This
allows unified analytics and correct tracking of pages that can be
accessed from multiple different URLs.
If your analytics library takes the page URL from the browser, you might need to override that behavior to use the canonical URL that is given to the method.
Initialise the handler in the
setupAnalyticsHandlers() function in