This service is used to keep track of the different events of our application in a centralised way. The service will depend on external javascript modules, and providers libraries loaded from the HTML template.
This is mandatory, as the analytics libraries must be loaded even before React or any other library.
Involved files
/src
/static
/index.ejs -> Template. We can place the scripts of the analytics providers here to load them on
/services
/analytics
index.js
analytics.js
/provider
/analytics
/{provider} -> Each provider __must__ export one function as default. It will be added to the analyticsProvider object to iterate over it
index.js
{provider}.js
/webpack
/local
/dev-config.js
Description
/webpack/webpack.common.js
This file contains the HtmlWebpackPlugin from webpack that allow us to pass variables to the template (index.ejs) file. i.e Google Tag Manager identifier
/src/static/index.ejs
EJS Template used by the HtmlWebpackPlugin. We can modify it to include new libraries. This allow us to initialise the analytics libraries before react is initialised
/src/services/analytics/analytics.js
Analytics service. Load the module and exposed methods to send analytics. We must modify this file to include or remove providers
/src/services/analytics/provider/provider.js
Analytics providers. They must export one function with the same name than the file (by convention) that sends the event to the provider
Members
# static constant devicePaired
Set the user into the analytics service and trigger the event actions fo the device pairing
# static constant userLoggedInStart
The user start the login process and tried to login into the application
# inner constant defaultProps
Default Properties to be used in all the events as defined in https://accedobroadband.jira.com/wiki/spaces/VDK/pages/2329674845/Service+Build+Elevate+Analytics+Service#Default-Properties
Methods
# inner sendEvent(event, opts, filter) → {boolean}
Send Event method. This method is a placeholder to call the different 'native' lib methods to trigger the analytics. It iterates over all the providers on the analyticsProviders object, filters the desired providers (if any) and call the function with the object containing the event and the payload
Parameters:
Name | Type | Description |
---|---|---|
event |
string
|
Event name. Needed in most of the libraries |
opts |
object
|
Event options. We can |
filter |
Array.<string>
|
If present, it only send the events to the desired analytic providers. i.e ['gtm', 'mux'] |
true if everything is ok, false if not
boolean