@global-savings-group/extension-megatron
v1.3.7
Published
Megatron analytics library
Downloads
193
Readme
Megatron analytics library
Requires next permissions in manifest.json:
alarms
- send keep-alive notificationsstorage
- store customerHash and last keep-alive notification date
Usage
Init Megatron singleton object anytime when all required params loaded/available:
import { BusinessModel, megatron } from '@global-savings-group/extension-megatron';
await megatron.init({
apiUrl: '{API URL}',
businessModel: BusinessModel.Conversion, // optional field, ask BI team for value
customerHash: '{customerHash}', // customerHash as string or undefined for auto-generation
trackId: '{track ID}', // ask BI team for unique trackId
trackUrlPrefix: 'https://website', // automatic URL prefix for "/page/urls"
version: chrome.runtime.getManifest().version,
});
Track page view (can be called even before .init()
):
import { megatron } from '@global-savings-group/extension-megatron'
// `trackUrlPrefix` will be added automatically before for all URLs started with "/"
await megatron.trackPageView({
title: 'optional page title',
url: '/page/url'
});
Keep alive notifications:
import { megatron } from '@global-savings-group/extension-megatron'
// Recommended check interval is 5-10 minutes, Megatron will send it only once per 24h
chrome.alarms.create('megatron:ping', { periodInMinutes: 10 });
// add global onAlarm listener or add logic to the beginning of existing listener
chrome.alarms.onAlarm.addListener((alarm) => {
if(alarm.name === 'megatron:ping'){
megatron.init({...});
megatron.ping();
return;
}
// ... other event handlers
});