analytics-plugin-etracker
v1.0.0
Published
etracker plugin for the analytics module
Maintainers
Readme
etracker Plugin for analytics
etracker integration for analytics, a lightweight open-source frontend analytics abstraction layer.
Installation
Install analytics and analytics-plugin-etracker packages.
npm install analytics
npm install analytics-plugin-etrackerSetup
Initialize the plugin with analytics.
import Analytics from 'analytics'
import etrackerPlugin from 'analytics-plugin-etracker'
const analytics = Analytics({
app: 'awesome-app',
plugins: [
etrackerPlugin({
secureCode: 'XXXXXX',
})
]
})secureCode is the etracker account key/security code from Settings → Integration → Tracking code.
Usage
The plugin loads etracker's tracking script and sends data whenever analytics.page or analytics.track is called.
If you already include the etracker tracking script in your templates, remove it to avoid double tracking.
/* Track a page view */
analytics.page({
title: 'Cart'
})
/* Track a custom event */
analytics.track('Add', {
category: 'Cart',
objectName: 'Ice Cubes',
type: 'click'
})API
Core methods
- analytics.page - Send a virtual page view through
et_eC_Wrapper. - analytics.track - Send an etracker user-defined event.
Plugin methods
updateCookieConsent(consented)
Grant or revoke cookie consent through etracker's cookie API.
analytics.plugins.etracker.updateCookieConsent(true)
analytics.plugins.etracker.updateCookieConsent(false)Configuration
Registration
secureCode— etracker account key/security code. Required.scriptUrl— Custom tracking script URL. Defaults to//code.etracker.com/code/e.js.
Privacy & Cookies
blockCookies— Adddata-block-cookiesto run etracker without cookies until consent is granted. Default:false.respectDoNotTrack— Adddata-respect-dnt. Default:true.cookieDomain— Domain passed toenableCookiesanddisableCookies. Defaults towindow.location.hostname.scriptAttributes— Additional loader attributes, for example CMP bypass attributes.
Single-Page Applications
The plugin sends manual virtual page views through et_eC_Wrapper when analytics.page() is called. etracker reads the URL from document.location.href; custom URLs passed to analytics.page() are not forwarded.
Consent Handling
Set blockCookies: true to make the loader receive data-block-cookies="true" so etracker can run without cookies until consent is granted. Call updateCookieConsent(true) after cookie consent is granted, and updateCookieConsent(false) after consent is revoked.
const analytics = Analytics({
app: 'awesome-app',
plugins: [
etrackerPlugin({
secureCode: 'XXXXXX',
blockCookies: true,
cookieDomain: 'example.com',
})
]
})
// Later... grant cookie consent from consent dialog
analytics.plugins.etracker.updateCookieConsent(true)Supported Platforms
The etracker plugin works in the browser. Node is currently not supported.
License
MIT
