# analytics.json

The analytics.json is the Marfeel resource file to declare analytics providers. To ensure Marfeel Analytics Schema plays well with AMP standards, every provider must extend the corresponding AMP data model (opens new window), adding support for our Touch configuration when necessary.

There are 4 differences between Marfeel analytics.json and AMP data model:

  • A new field touchVars: an object that contains variables that are ONLY used in the Touch implementation.
  • The request field of triggers is renamed to action
  • The platform (AMP, touch, native) can be selected for the whole provider or for a specific trigger
  • Triggers can be extended

This article describes the purpose of each possible field of an Analytics Provider configuration in the analytics.json file.

# vars (opens new window)

This is a required field for the variables that are referenced in an AMP's request.

The variables are usually specified in the vendor's implementation. AMP documentation (opens new window) contains all the AMP-compatible vendors.

In Google Analytics configuration (opens new window) for example, the pageview request requires an account variable ((tid=${account})).

In Marfeel it can be defined as:

{
  "vars": {
    "account": "THE UA CODE HERE"
  }
}

# extraUrlParams (opens new window)

The extraUrlParams (opens new window) field is an optional object for additional parameters.

They depend on each site's requirements. For example, a site can choose to send custom, additional information to their analytics provider:

{
  "vars": {
    "account": "THE UA CODE HERE"
  },
  "extraUrlParams": {
    "foo": 123,
    "myOtherVariable": "someValue"
  }
}

foo=123&myOtherVariable=someValue are appended as query parameters.

TIP

Extra Params are sent both in AMP and Touch pages.

# touchVars

touchVars is an optional Marfeel-specific field, used only in Touch.

In Marfeel's legacy implementation of Google Analytics, there is an environment variable (opens new window).

It can be sent to the Analytics Typescript implementation with:

{
  "vars": {
    "account": "THE UA CODE HERE"
  },
  "touchVars": {
     "environment": "THE_VALUE_WE_WANT"
  }
}

# triggers (opens new window)

The triggers (opens new window) configuration object describes when an analytics request should be sent. The triggers attribute contains a key-value pair of trigger-name and trigger-configuration.

The trigger-configuration supports all the standard AMP fields (opens new window).

Reminder

The AMP request field is renamed to action in Marfeel configuration.

# On

This is a required field.

It represents the event that the provider is listening for. Marfeel Core uses the same specification as AMP in order to trigger the events that are supported in both. However, we have introduced more events to cover all scenarios for any interaction within Marfeel.

# Action

This is a required field.

AMP's trigger configuration uses the field request. In Marfeel this field name is replaced by action, with the exact same purpose. action represents the name of the request to send.

The action defines the method to trigger in our Typescript implementation. This field is translated behind the scenes to request when the tracker is printed in Marfeel's AMP version.

Standardization

These action fields follow AMP's data model. This means that the methods we implement must have the same names as in AMP.

e.g: Let's take google analytics. In the legacy metrics, the method to track a page view was called trackVirtualPage here (opens new window) In AMP's data model the request name to track a page view is called pageview, and since the providers follow AMP's data model the action field will have pageview as value:

{
  "touchVars": {
    "environment": "THE_VALUE_WE_WANT"
  },
  "triggers": {
    "trackVirtualPage": {
      "on": "visible",
      "action": "pageview"
    }
  }
}

Triggers key

The triggers' key name does not matter at all. You can use any name but remember to use descriptive names.

# Vars, extraUrlParams, touchVars

Inside a trigger configuration, we can have a specific configuration of vars, extraUrlParams and touchVars.

e.g:

{
  "vars": {
    "account": "SOME ACCOUNT HERE"
  },
  "extraUrlParam": {
    "cd1": "SOME VALUE"
  },
  "triggers": {
    "trackVirtualPage": {
      "platforms": ["AMP"],
      "on": "visible",
      "action": "pageview",
      "extraUrlParams": {
        "cd23": "someSpecific Value for AMP"
      }
    }
  }
}

# platforms

This optional field represents the platform where an analytics provider is instantiated. It supports:

  • AMP,
  • TOUCH,
  • CHEROKEE.

Use it once for the whole provider, or differentiate per trigger:


 





{
  "platforms": ["TOUCH"],
  "vars": {
    "account": "THE UA CODE HERE"
  }
}






 






{
  "vars": {
    "account": "THE UA CODE HERE"
  },
  "triggers": {
    "trackTenantPageview": {
      "platforms": [ "TOUCH" ],
      "on": "visible",
      "action": "pageview"
    }
  }
}

# middleware

Add a middleware to extract information from pages dynamically.
















 




{
  "googleanalytics": [
    {
      "vars": {
        "account": "XXXXXXXX"
      },
      "touchVars": {
        "environment": "#{env.device.environment}"
      },
      "triggers": {
        "triggerTest": {
          "on": "visible",
          "action": "pageview"
        }
      },
      "middleware": "ugaCustomEvents"
    }
  ]
}

# extends

Triggers can use field inheritance in order to extend and add default triggers:

{
  "vars": {
    "account": "THE UA ACCOUNT HERE"
  },
  "triggers": {
    "__extends": "marfeel/index/resources/analytics/triggers/googleanalytics/pageview.json"
  }
}

You can find the default triggers in MarfeelXP (opens new window).