Exodus analytics
A base class encapsulating analytics integration.
API Reference
Property name | Description |
---|
setPermanentUserId | Use this to set the permanent user id, i.e. the seed derived id fetched from analyticsUserIdAtom |
flush | Use this to send persisted events to segment. Events that are track ed before setPermanentUserId is set will need to be flushed |
getAnonymousId | Gets the anonymousId associated with the tracker. This is a UUID until setPermanentUserId is called with the userId |
track | Use this method to send events to segment. If setPermanentUserId has not been called, you must use force: true . |
identify | Used primarily to identify a user with the onboarding UUID and to set global "traits". Should be used sparingly -- on seed import or seed create for example. |
setDefaultProperties | Pretty much as it sounds. This sets persistent properties to be sent with every call to segment via track |
trackInstall | sets a persisted event that can be sent with flush postinstall |
Usage
import createStorage from '@exodus/storage-memory'
import analyticsDefinition from '@exodus/analytics'
import Tracker from '@exodus/segment-metrics'
const analytics = analyticsDefinition.factory({
storage: storage.namespace('analytics'),
shareActivityAtom,
tracker: new Tracker(segmentApiKey),
config: {
installEventReportingUrl,
},
logger,
})
analytics.track({ ...onboardingEvent, force: true })
analytics.track({ ...anotherEvent })
const userId = await analyticsUserIdAtom.get()
analytics.setPermanentUserId(userId)
analytics.flush()
analytics.track({
event: 'hello world',
})
Constructor Options
Property name | Required | Description |
---|
tracker | yes | A Tracker class instance. |
storage | yes | An object implementing the Storage interface (see below). Needed if you need to persist events (e.g. when a consumer application can be temporarily locked). |
shareActivityAtom | yes | An atom returning a boolean value indicating if a consumer application is ready to send events. |
trackUnvalidated | no | A boolean flag indicating if not validated events should be still submitted to Segment API. false by default |
config | no | Static configuration options |
config.installEventReportingUrl | no | Url to which to post app install events |
type SerializedEvent = 'string'
interface Storage {
set: (key: string, events: SerializedEvent[]) => Promise<undefined>
get: (key: string) => Promise<SerializedEvent[]>
}