Skip to main content
Install the Twinalyze JavaScript Analytics SDK and initialize it once when your website or application starts.

Add the SDK dependency

Choose your preferred installation method.

Initialize the SDK

Add this Javascript sdk script to your code and your SDK is ready to send events.
Replace YOUR_API_KEY and YOUR_SECRET_KEY with the credentials available in your Twinalyze project.
Initialize the SDK only once. After initialization, Twinalyze creates the device and session identifiers and starts collecting supported website events.

Enable Firebase Cloud Messaging

The complete configuration allows you to manage sessions, automatic event tracking, site search, file downloads, and Firebase Cloud Messaging.
To enable web push notifications, create the following service worker file:
The final file must be publicly available at:
To enable web push notifications, download the Twinalyze Firebase service worker file.

Twinalyze FCM Service Worker

Download the worker file and add your Firebase configuration.

twinalyze-fcm-sw.js

Place this file in your application’s public root directory.

Request notification permission

Notification permission must be requested after a user action, such as clicking an Enable Notifications button. Call the function from a button:
FCM works only when the browser supports notifications, FCM is enabled, the service worker is publicly available, and notification permission is granted.