1.3.0-PMT-streamline-build.2 • Published 2 years ago

@lemonstand.org/unified-tracking v1.3.0-PMT-streamline-build.2

Weekly downloads
-
License
UNLICENSED
Repository
gitlab
Last release
2 years ago

unified tracking

An abstraction over sending tracking events; use the same interface for both backend and frontend.

Usage

Install via NPM:

npm install @lemonstand.org/unified-tracking

Import appropriately, depending on environment:

// - for browser
import EventTracker from '@lemonstand.org/unified-tracking'

// - for nodejs
import EventTracker from '@lemonstand.org/unified-tracking/node'

Then, initialize an EventTracker object, ideally in a global scope:

const eventTracker = new EventTracker("https://lemonstand-test-ct.goodgamestudios.com/");
...
// once an event of interest is detected
const commonData = {gameId, networkId, instanceId, playerId, ...};
eventTracker.send(TRACKING_EVENT_OF_INTEREST.decorate(commonData, "custom1", "custom2", ...));

This module creates two bundles, one for the browser and one for a node runtime. The browser bundle sends requests via the built-in Beacon API (so apply polyfills as necessary) while the node bundle sends requests via the got library.

Arguments to eventTracker.send

The trackingParams is an object of three fields: event, endpoint and data.

  • event (TrackingEvent) is a data object that maps to Data Warehouse's Tracking Event Data.
  • endpoint (string) is the tracking URL which we make a request to.
  • data (extends CommonTrackingEventData) is an object containing the data sent to endpoint. The common data fields are encoded in the type CommonTrackingEventData. The type encoding allows for the addition of custom fields.

eventTracker.send also takes in variadic arguments of any type that would be the additional fields of each tracking event. Check the documentation of the event you are using for the proper order of parameters.

How to add new events

When adding new tracking events, we should follow some criterias in order to keep the definition organized 1. Create a file for the tracking context if the new events don't fit any of the existing ones e.g. lemonstand-events, ads-events... 2. Describe your events cohesively, based on purpose/origin rather than TEDs. e.g. AC_LEMONSTAND_CLOSE 3. Follow the naming conventions, paying attention to the prefix in the event name, AC and ST. * It stands for ACtion and STate. e.g.: - AC_LEMONSTAND_CLOSE -> When the user closed Lemonstand (Action) - ST_RELOAD_AFTER_SUCCESS -> The state is triggered from successful transaction/payment (State) 4. Export everthing by default and import the new created file in the events/index.ts 5. Deploy and import it in the desired projet

```ts
  import { EventTracker, ST_OFFER_PURCHASED } from '@lemonstand.org/unified-tracking/dist/NodeEventTracker';
  const eventTracker = new EventTracker(env.TRACKING_SERVICE_URL);
  eventTracker.send(ST_OFFER_PURCHASED.decorate(
    commonData,
    parseInt(offer.id, 10),
    parseInt(reward.wodId, 10),
    reward.qty,
    env.getTrackingType(category)
  ));
```
1.3.0-qa.1

2 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.1-qa.1

3 years ago

1.2.0-qa.1

3 years ago

1.1.0-qa.1

3 years ago

1.0.0

3 years ago

0.1.15-IGS1770

3 years ago

0.1.14-IGS1770

3 years ago

0.1.13-IGS1770

3 years ago

0.1.12-IGS1770

3 years ago

0.1.11-IGS1770

3 years ago

0.1.10-IGS1770

3 years ago

0.1.9-IGS1770

3 years ago

0.1.8-IGS1770

3 years ago

0.1.7-IGS1770

3 years ago

0.1.6-IGS1770

3 years ago

0.1.5-IGS1770

3 years ago

0.1.4-IGS1770

3 years ago

0.1.3-IGS1770

3 years ago

0.1.2-IGS1770

3 years ago

0.1.1-IGS1770

3 years ago

0.1.0-IGS1770

3 years ago