Google Analytics

You can quickly and easily add Google Analytics to your Mattercraft project via the Dependencies Browser.

To set up analytics for your Mattercraft project, you must have a tracking ID. You can find this using Google's documentation.

Installing Google Analytics

Adding Google Analytics using the Dependencies Browser
  1. Open the Dependency Browser and ensure you are in the Recommended tab
  2. Click on the Analytics category (or find the relevant analytics platform package in the Popular section)
  3. Find the Google Analytics package and click on it to open the information dialog
  4. Click on the Install button, which will instantly install the dependency to your project

Using Google Analytics in a Behavior Action

Using Google Analytics in the Hierarchy and Behavior Action panels
  1. Add the Google Analytics component to your Hierarchy by going to New + and then Analytics
  2. Click on the analytics component in the Hierarchy and add your tracking ID to the Node Properties panel
  3. Add a Log Analytics Event Behavior Action to a component you want to get data from

Analytics will not be logged when you preview your experience. To start logging data, your project must first be published.

Using Google Analytics in a script

You can make use of the .logEvent() method when scripting. Below is an example Custom Behavior which logs a message when a button has been tapped.

// Imports...

interface ConstructionProps {
    // Add any constructor props you'd like for your behavior here
}

/**
 * @zbehavior 
 * @zparents three/Object3D/Image
 **/
export class LogEvent extends Behavior<Image> {

    protected zcomponent = this.getZComponentInstance(Scene);


    constructor(contextManager: ContextManager, instance: Image, protected constructorProps: ConstructionProps) {
        super(contextManager, instance);

        // Target the Analytics component and log an event
        this.zcomponent.nodes.GoogleAnalytics.logEvent("Button Tapped!", {'eventCategory': 'Engagement'});

    }

    dispose() {
        // Clean up any resources
        // ...
        return super.dispose();
    }
}

// Uncomment below to run this behavior at design time
// registerBehaviorRunAtDesignTime(LogEvent);

Analytics will not be logged when you preview your experience. To start logging data, your project must first be published.

zapcode branded_zapcode i