javascriptjsontypescriptgoogle-analyticsmodel-viewer

How to change the default value of "non-interaction" events in Google Analytics


I'm using Google's Model Viewer in my project, and unfortunately, it is treating certain events as non-interaction: false when they should be non-interaction: true. In my case, these are the events that fire when the model loads, when it detects a user with AR support, and when it detects a user with QR support.

How can I manually set the non-interaction values of these events to true? I've attempted solutions similar to this to no avail:

export type AnalyticsEvent = {
  type: string;
  category: string;
  action: string;
  label: string;
  value: number;
  nonInteraction: boolean;
};
export const USER_WITH_AR_SUPPORT_TEMPLATE: AnalyticsEvent = {
  type: 'event',
  category: AR_CATEGORY,
  action: 'UserWithArSupport',
  label: '',
  value: '',
  nonInteraction: true,
};
"kind": "javascript-module",
"path": "src/globals/ArEvents.ts",
"declarations": [
  {
    "kind": "variable",
    "name": "userWithArSupportTemplate",
    "type": {
      "text": "AnalyticsEvent"
    },
    "default": "{\n  type: 'event',\n  category: ARCategory,\n  action: 'UserWithArSupport',\n  label: '',\n ,\n nonInteraction: true}"
  },

I've also attempted the solution here, as well as several similar ones. Am I using the wrong variable name or index for non-interaction?

Added more code as requested

public sendGaEvent(uaCode: string, eventData: AnalyticsEvent, sku: string, log: boolean) {
    ...
    const instance = this[$analyticsMap].get(uaCode);
    const tracker = instance!.tracker;
    if (!tracker) {
      const queue = instance!.queue;
      queue!.enqueue(eventData);

      LoggerInstance.log({
        sender: this,
        message: 'Enqueuing GA event',
        force: log
      });
    } else {
      ga(`${tracker}.send`, 
        eventData.type,
        eventData.category,
        eventData.action,
        eventData.label,
        eventData.nonInteraction,
        {
          hitCallback: () => LoggerInstance.log({
            sender: this,
            message: 'GA event successfully sent!',
            objectToLog: eventData,
            force: log
          })
        }
      );

      LoggerInstance.log({
        sender: this,
        message: 'Sending GA event',
        force: log
      });
    }
    ...
}

EDIT: Using @d-_-b's suggestion, I found the proper form of the solution to be passing in nonInteraction as an object as follows:

ga(
   'send', 
   'event', 
   'AR_CATEGORY', 
   'UserWithArSupport', 
   'label', 
   {'nonInteraction': true}
);

It is evidently important to keep the quotes around the name 'nonInteraction' when passing it in as an object


Solution

  • For Universal Analytics, the nonInteraction property should be passed as an object (see docs):

    ga('send', 'event', 'AR_CATEGORY', 'UserWithArSupport', 'label', {
      nonInteraction: true
    });
    

    If you're using gtag.js, you need to add non_interaction: true as documented here

     gtag('event', '<event-name>', {
       'event_label': '',
       'event_category': 'AR_CATEGORY',
       'event_action': 'UserWithArSupport',
       'non_interaction': true
     });