@lemonstand.org/unified-tracking v1.3.0-PMT-streamline-build.2
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 toendpoint
. The common data fields are encoded in the typeCommonTrackingEventData
. 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 AC
tion and ST
ate.
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)
));
```
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago