# Analytics.json: Variables Replacement

The Touch configuration of any Analytics Provider can make references to Marfeel-specific variables, and get their value at trigger-time.

The information available is very varied, for example from the device type of the reader to the last user action, such as "swiped left".

All variables meant to be replaced must be surrounded by #{}:

#{env.device.environment}

The replacement does not happen if the requested variable doesn't exist.

No AMP compatibility

Only Marfeel Touch supports variable replacement.

# Marfeel Environment Replacements

Example:

Marfeel Google Analytics Touch implementation requires the referrer site. Marfeel environment provides it via location:








 





{
  "googleanalytics": [
    {
      "vars": {
        "account": "UA-XXXXXX-X"
      },
      "touchVars": {
        "referrer": "#{env.location.href}"
      }
    }
  ]
}

If the current location.referrer is https://testme.mrf.io, all Google Analytics action methods receive:








 





{
  "googleanalytics": [
    {
      "vars": {
        "account": "UA-XXXXXX-X"
      },
      "touchVars": {
        "referrer": "https://testme.mrf.io"
      }
    }
  ]
}

# Function replacements

Marfeel Environment also contains functions, to retrieve dynamic information.

It is for example possible to get the current section name:








 





{
  "googleanalytics": [
    {
      "vars": {
        "account": "UA-XXXXXX-X"
      },
      "touchVars": {
        "sectionName": "#{env.location.getSection().name}"
      }
    }
  ]
}

The result is:








 





{
  "googleanalytics": [
    {
      "vars": {
        "account": "UA-XXXXXX-X"
      },
      "touchVars": {
        "sectionName": "sports"
      }
    }
  ]
}

The getSection function is called before every trigger, effectively sending the right section name every time.

# Current Event Replacements

All events in Marfeel Core broadcast with a specific payload.

During the variable replacement phase, the provider's configuration can also reference any event's payload.

For example, the navigation event has direction with value left or right. direction is available in the event object with its value.








 





{
  "googleanalytics": [
    {
      "vars": {
        "account": "UA-XXXXXX-X"
      },
      "touchVars": {
        "direction": "#{event.direction}"
      }
    }
  ]
}

The result would be:








 





{
  "googleanalytics": [
    {
      "vars": {
        "account": "UA-XXXXXX-X"
      },
      "touchVars": {
        "direction": "left"
      }
    }
  ]
}

Know the events

It is up to developers to know which events broadcast which variables to know how to use them. Check all Marfeel events implementation (opens new window) for more details.