Javascript API Reference

API Reference

Once you have installed initialized the Fanplayr 360 library you will have access to a global variable window.fp360.

This object will have the following functions.

consent.set

fp360.consent.set(consentKey:string, consentValue:string, {
    purpose: Array<{
        type: string,
        topics?: string[]
    }>
}?);

consent.unset

fp360.consent.unset(consentKey:string, consentValue:string);

flush

fp360.flush(function() {
  // Fanplayr 360's events have been successfully tracked and the user can
  // be navigated to another page.
});

identify

fp360.identify({
  [identifyKey: string]: string
})

init

fp360.init({
  writeKey: string
  endpoint: string
  autoStartSession: boolean = false
  batchFlushDelayMs: number = 1000 // 1 second
  sessionDurationMs: number = 45 * 60 * 1000, // 45 minutes
  cookieExpiration: number = 365 // 1 year
  storageKey: string = 'fp360'
  storageType: 'localStorage'
  idMaxAgeMs: number = 60 * 60 * 1000, // 1 hour
  ip: boolean = true
  debug: true | false | 'none' | 'info' | 'verbose' = false
});

page

fp360.page({
    type: string,
    name?: string
})

track

fp360.track(eventName: string, {
    [attributeKey: string]: string | number | boolean | {
        [semanticAttributeKey:string]: string | number | boolean
    }
})

user.set

fp360.user.set({
    [userAttributeKey: string]: string | number | boolean
}, { expires: string, number, Date }?)

If you are only setting a single value you can call it like this:

fp360.user.set(
    userAttributeKey: string,
    value: string | number | boolean,
    { expires: string, number, Date }?
)

user.setOnce

fp360.user.setOnce({
    [userAttribute: string]: string | number | boolean
}, { expires: string, number, Date }?)

If you are only setting a single value you can call it like this:

fp360.user.setOnce(
    userAttributeKey: string,
    value: string | number | boolean,
    { expires: string, number, Date }?
)

user.unset

You can unset multiple values at once:

fp360.user.unset(userAttributeKeys: string[])

Or a single value:

fp360.user.unset(userAttributeKey: string)

user.increment

fp360.increment(userAttributeKey: string, value:number = 1)

setConfig

fp360.setConfig({
  writeKey: string
  endpoint: string
  autoStartSession: boolean = false
  batchFlushDelayMs: number = 1000 // 1 second
  sessionDurationMs: number = 45 * 60 * 1000, // 45 minutes
  cookieExpiration: number = 365 // 1 year
  storageKey: string = 'fp360'
  storageType: 'localStorage'
  idMaxAgeMs: number = 60 * 60 * 1000, // 1 hour
  ip: boolean = true
  debug: true | false | 'none' | 'info' | 'verbose' = false
});

setSessionId

fp360.setSessionId(sessionId: string)

setUserId

fp360.setUserId(uniqueUserId: string);

Config Reference

{
  // The write key generated from a Source integration.
  writeKey: string
  // The tracking endpoint to use, will differ depending on data storage region.
  endpoint: string
  // Whether to enable debug logging in the browser console.
  // Values `false` and `'none'` turn debugging off
  debug: true | false | 'none' | 'info' | 'verbose' = false
  // Set to `false` if using with Fanplayr Targeting.
  autoStartSession: boolean = true
  // The delay before sending batches of tracking data.
  batchFlushDelayMs: number = 1000 // 1 second
  // How long should a session last after last event.
  sessionDurationMs: number = 45 * 60 * 1000, // 45 minutes
  // How long the cookie should last - most browsers will ignore this.
  cookieExpiration: number = 365 // 1 year
  // The key in localStorage to store local Fanplayr 360 data.
  storageKey: string = 'fp360'
  // Where to store local data.
  storageType: 'localStorage'
  // The maximum duration to cache calls to `identify()`. This cache prevents
  // unnecessary requests when the `identify()` API is repeated with the same input.
  idMaxAgeMs: number = 60 * 60 * 1000, // 1 hour
  // When enabled, Fanplayr will use the client's IP address to determine geolocation.
  ip: boolean = true
}

Last updated