Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
// Log your event
collector.logEvent("Server CLI Request", formattedEvent)
  .then((analyticsEvent) => {
    // The logEvent() method returns a Promise
    // that resolves to the event
    // sent to the analytics service
    console.log(analyticsEvent)
  })
  .catch((err) => {
    throw Error(err)
  })



To send multiple custom events at once, we format our single events into an array of events, and use the logEvents() method:

Code Block
languagejs
// Format your events into an array
const formattedEvents =
[
  {
    category: "Videos",
    action: "Start",
    label: "HowTo",
    value: 1497509263823
  },
  {
    category: "Videos",
    action: "Stop",
    label: "HowTo",
    value: 1497509350209
  }
]

// Log your events
collector.logEvents("Server CLI Request", formattedEvents)
  .then((analyticsEvent) => {
    // The logEvents() method returns a Promise
    // that resolves to whatever was
    // returned from the Simple Analytics service,
    // currently the array of events that
    // was sent to Simple Analytics
    console.log(analyticsEvent)
  })
  .catch((err) => {
    throw Error(err)
  })


Congratulations! When this script is triggered, your custom events will now be logging to the BlinkMobile Simple Analytics Service Database.

...