4. Install the Logger

Add the Metalitix Logger to your Three.js experience

PlayCanvas Integration Guide

  1. Within your PlayCanvas project, navigate to Settings -> External Scripts. Add the URL beloww to the array. This script adds a global constructor called MetalitixLogger.

    https://cdn.metalitix.com/logger/play-canvas/latest/play-canvas.js
  2. Next, open the Code Editor and create a new Script Asset. Copy the PlayCanvas Camera Script below and paste it into the editor.

PlayCanvas Camera Script
var Metalitix = pc.createScript('metalitix');

Metalitix.attributes.add('apiKey', {
  type: 'string',
  title: 'API Key',
  description: 'Within your project settings on Metalitix you will find an `apiKey`.'
});

Metalitix.attributes.add('survey', {
  type: 'boolean',
  default: true,
  title: 'Show survey',
  description: 'Whether to randomly survey the user for their opinion on engagment. Engagement level is a 1 to 5 first-hand rating of user sentiment. By default, this is true and done randomly between 30 seconds and 3 minutes.'
});

Metalitix.attributes.add('surveyTheme', {
  type: 'string',
  default: 'white',
  enum: [
    { 'white': 'white' },
    { 'black': 'black' }
  ],
  title: 'Survay theme',
  description: 'The color theme of the engagement level prompt (`white` or `black`). By default, it is `white`.'
});

Metalitix.attributes.add('object3D', {
  type: 'entity',
  title: 'Object3D',
  default: null,
  description: 'The Entity to keep track camera position'
});

// initialize code called once per entity
Metalitix.prototype.initialize = function() {
  var logger = new MetalitixLogger(this.apiKey, {
    pollInterval: this.interval,
    apiVersion: this.apiVersion,
    showSurvey: this.survey,
    surveyTheme: this.surveyTheme,
  });

  logger.startSession(this.entity, this.object3D);
};
  1. Return to the scene editor, and from the Hierarchy select your Camera Entity. Within your camera's Script Component, add the name of the camera script you just created.\

  2. You will find the API Key within your project settings in the Metalitix dashboard. Copy and paste this value into the the API Key setting in the script added to the camera.\

  3. Metalitix is now configured to gather analytics on your project! 🎉 To test, engage with your experience to create a session. Then, navigate to the Sessions tab within your project on the Metalitix dashboard. Within a few minutes, you will see your session appear at the top of the table. It will be marked as Active until the session ends. When a session no longer says Active, its data will appear on the Metrics tab. Heatmap data, on the other hand, is calculated in real-time for small projects and every 24 hours for large projects.

Last updated