Developer Hub

Use cases > Analytics events > Analytics Events

Analytics

Analytics Events

When to Use?

Whenever a user performs an action in the turnkey portal, Fluid Topics sends the event to its analytics platform. It is possible to configure the custom.js file to also send the event to a different analytics platform.

By listening to a JavaScript event, it is possible to retrieve the analytics events that the turnkey portal generates in order to send them to an in-house analytics stack.
The following lines show an example:
document.addEventListener('ft:analytics:userevents', function(event){
  let events = event.detail;
  for (let event of events) {
    switch (event.name) {
      case 'topic.start_display':
        sendAnalytics({
          type: 'topic display',
          documentId: event.parameters.document.originId,
          documentTitle: event.parameters.document.title,
          topicId: event.parameters.document.topicId
        });
        break;
      case 'document.start_display':
        sendAnalytics({
          type: 'document display',
          documentId: event.parameters.document.originId,
          documentTitle: event.parameters.document.title
        });
        break;
    }
  }
});

function sendAnalytics(analytics) {
  var xhr = new XMLHttpRequest();
  xhr.open("POST", "http://my.analytics.server/path", true);
  xhr.setRequestHeader('Content-Type', 'application/json');
  xhr.send(JSON.stringify(analytics));
}

@ Copyright 2021, Antidot • All rights reserved.