@global-savings-group/extension-megatron
TypeScript icon, indicating that this package has built-in type declarations

1.3.7 • Public • Published

Megatron analytics library

Requires next permissions in manifest.json:

  • alarms - send keep-alive notifications
  • storage - 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
});

Readme

Keywords

none

Package Sidebar

Install

npm i @global-savings-group/extension-megatron

Weekly Downloads

6

Version

1.3.7

License

none

Unpacked Size

10.5 kB

Total Files

10

Last publish

Collaborators

  • yuriy_khabarov_gsg
  • gsg_system