CustomEvent

CustomEvent

Creates an instance of CustomEvent.

Constructor

new CustomEvent(name, valueopt, propertiesopt, transactionIdopt)

Properties:
Name Type Description
name String

This event's name. Read only. 255 character limit.

value Number

This event's value.

transactionId String

Multiple Events can be given the same transactionId to group them together in reports. 255 character limit.

interactionId String

Defaults to the url of the page that triggered this event. 255 character limit.

If window.location.href.length > 255 this will be set to "${href.slice(0, 230)}...${SHA(href).slice(0, 20)}" on track().

interactionType String

Defaults to url. 255 character limit.

properties.* String | Array | Number | Boolean

All string properties have a 255 character limit.

Parameters:
Name Type Attributes Default Description
name String
value Number <optional>
properties Object <optional>
{}
transactionId String <optional>
Throws:
  • name is a required argument.

    Type
    ReferenceError
  • The name passed in is not a string.

    Type
    TypeError
  • The value passed or assigned is not a number.

    Type
    TypeError
  • There is no channel registered in the sdk.

    Type
    ReferenceError
Example
const myEvent = new sdk.CustomEvent('ate_food')
myEvent.value = 34.5
myEvent.properties.breakfast = 'pancakes'
myEvent.track()
  .catch(err => {
    // see validate() below
  })
// The same:
new sdk.CustomEvent('ate_food', 34.5, {breakfast: 'pancakes'})
  .track() // ==> Promise

Methods

(async) track() → {Promise}

Validates and tracks the custom event.

Returns:
Type:
Promise

Resolves to {ok: true, operation_id} on success.

Rejects any error found in CustomEvent#validate.