SDK di Analytics del tracker

Scopri come configurare e usare lo SDK di analytics del tracker di OpenReplay

SDK di Analytics del tracker

Scopri come configurare lo SDK di analytics del tracker di OpenReplay.

Lo SDK di analytics è opt-in. Viene istanziato solo quando passi analytics.active al costruttore del tracker: fino ad allora tracker.analytics è null e tracker.track() non fa nulla.

import Tracker from '@openreplay/tracker'

const tracker = new Tracker({
  projectKey: "YOUR_PROJECT_KEY",
  analytics: { active: true },
})

tracker.start()
  • active: boolean Attiva lo SDK di analytics. Predefinito: false.
  • ingestPoint?: string Endpoint a cui vengono inviati i batch di analytics. Solo per i deployment self-hosted: su OpenReplay Cloud viene ignorato e si usa https://api.openreplay.com/ingest. Per impostazione predefinita usa l’ingestPoint del tracker.

Per saperne di più sulla gestione dei dati di analytics nell’interfaccia di OpenReplay, visita Gestione dei dati.

// Identify a user with an id (e.g. email, username, etc.)
tracker.analytics.identify(userId: string): void
// same as
tracker.analytics.people.identify(userId)

// Add event to batch with option to send it immediately
tracker.analytics.track(eventName: string, tempProperties?: Record<string, any>, options?: { send_immediately: boolean })
// same as
tracker.analytics.events.track(eventName, tempProperties, options)

// Clear user id, people properties and super properties, and stop the batcher
tracker.analytics.reset(): void

Scorciatoie a livello di tracker

Section titled Scorciatoie a livello di tracker

Si trovano sul tracker stesso, quindi puoi chiamarle senza passare da tracker.analytics (non fanno nulla finché analytics è disattivato):

// Same as tracker.analytics.track(...)
tracker.track(eventName: string, properties?: Record<string, any>, options?: { send_immediately: boolean })

// Sets the replay's user ID *and* calls analytics.people.identify() with it
tracker.setUserID(id: string): void
tracker.identify(id: string): void // alias of setUserID

// Send analytics events under your own token, without session recording
tracker.setAnalyticsToken(token: string): void

Cancella l’utente identificato (incluso l’ID persistente del dispositivo), tutte le proprietà people, tutte le super properties e arresta il batcher. Chiamalo al logout.

tracker.analytics.reset()

Se riscontri problemi, collegati al nostro Slack e chiedi aiuto alla nostra community.