@turtlenetwork/event-sender
TypeScript icon, indicating that this package has built-in type declarations

0.4.4 • Public • Published

Event Sender

Build Status

An interface for sending analytics events from TN JS applications.


Usage:

import EventSender from '@turtlenetwork/event-sender';

// EventSender is a singleton, so any new attemps at instantiation
// will return a reference to a previously created instance
const sender = new EventSender();

// E.g.
const sender2 = new EventSender();
sender === sender2 // true


// Static method .inactive() returns an instance of EventSender that queues events,
// but does not send them until .activate() method is called
const sender = EventSender.inactive();

// (!) If an EventSender instance has been activated before, this will
// return a reference to it, so it WILL be active.



/** Queue custom event */
sender.push('Product', 'GetClientClick', 'my_custom_label', 2.0);

/**
 * Queue page view
 * Useful for SPA page transitions when no
 * pageView event is tracked by default.
 */
sender.pushPageView(window.location.href, document.referrer);


// Enables sending events, including those queued before.
sender.activate();


// EventSender methods are chainable:
sender
  .activate()
  .push('Product', 'GetClientClick', 'my_custom_label', 2.0)
  .pushPageView(window.location.href, document.referrer)
  .push('Home', 'Subscribe');

Readme

Keywords

none

Package Sidebar

Install

npm i @turtlenetwork/event-sender

Weekly Downloads

3

Version

0.4.4

License

Apache-2.0

Unpacked Size

13.6 kB

Total Files

5

Last publish

Collaborators

  • blackturtle