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

Namespaces

templates

Methods

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.

validate()

Should never have to be called manually.

Validates the event and throws any errors found. Is used by CustomEvent#track to reject any errors.

Throws:
  • A value with a required type is the wrong type.

    Type
    TypeError
  • All strings have 255 character limits.

    Type
    RangeError
  • Any properties that are arrays may only contain strings.

    Type
    TypeError
  • Any properties that are arrays have a max length of 20.

    Type
    RangeError