# Create a Metrics extension

Partially Deprecated

Metrics extensions are being phased out. They are only compatible with Legacy Media Groups.

For an XPLib tenant, you must use Analytics Providers.

If a metric provider is not supported by Marfeel, a new metric extension needs to be created. If it's the first time for this provider, the extension has to be created in the Tenant's code repository as a custom metric system. Otherwise, the extension has to be implemented in core to be available by default.

You can research if this provider already has a custom implementation via Github with this search URL, replacing ${PROVIDER_NAME} with the one you're looking for.

https://github.com/search?q=org%3AMarfeel+filename%3Ametrics+extension%3Ajson+custom+${PROVIDER_NAME}&type=Code

For example for Xiti: https://github.com/search?q=org%3AMarfeel+filename%3Ametrics+extension%3Ajson+custom+xiti&type=Code (opens new window)

# Custom metric extension

# Touch

First, the configuration is made in a custom js file. Then it is defined in metrics.json with the necessary attributes.

For example, the following snippet includes these fields:

  • type: the type of this metric extension, here (and most of the time) js.
  • file: the name of the file which has to be created in the src/js/features/metrics/ folder. No need for .js at the end.
  • params: the params which are going to be passed to the buildFromJson static method.
{
    "custom": [{
            "type": "js",
            "file": "XitiCustom", // www.examplesite.com/index/src/js/features/metrics/XitiCustom.js
            "params": {
                "site": "530172",
                "logs": "logc123",
                "domain": "http://logc123",
                "level2": "",
                "host": "http://www.examplesite.com/"
            },
            "platforms": [
                "TOUCH"
            ]
        }
    ]
}

TIP

The available attributes for these providers can be found in the custom metrics json schema (opens new window).

The custom js file should follow the same structure of a core metric, so it should be a class extending AbstractTracker with a constructor, a trackVirtualPage method and a buildFromJson static method which has to return a properly configured instance of the metric.

The custom metric class should extend AbstractTracker class or another core metric class.

import IframeBlankUtils from 'marfeel/commons/IframeBlankUtils';
import NeroTemplate from 'CustomJSFolder/../../../../examplesite.com/common/src/js/analytics/NeroTemplate.html';
import AbstractTracker from 'marfeel/touch/features/metrics/AbstractTracker';

export default class CustomNeroAnalytics extends AbstractTracker {
    static buildFromJSON() {
        return new CustomNeroAnalytics();
    }

    trackVirtualPage() {
        const tmpDiv = document.createElement('div');

        document.head.appendChild(tmpDiv);
        IframeBlankUtils.create(tmpDiv, NeroTemplate);
    }
}

# AMP

To create the metric extension for AMP, there are two options:

# Via JSON

This will define an amp-analytics (opens new window). The implementation can be found at Tenants/vhosts/marfeel/themes/default/tracker/customMetric.jsp.

These variables, which can be added in jsonContent, will be replaced at render time:

  • DATA_SOURCE
  • SECTION
  • DOCUMENT_LOCATION
  • DOCUMENT_TITLE
{
    "custom": [
        {
            "type": "json",
            "jsonContent": "{
                \"vars\": {
                    \"apid\": \"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\",
                    \"apv\": \"1.0\",
                    \"apn\": \"My AMP Website\",
                    \"section\": ${SECTION},
                    \"segA\": \"Music\",
                    \"segB\": \"News\",
                    \"segC\": \"Google AMP\"
                }
            }",
            "typeAttribute": "nielsen",
            "idAttribute": "tracker-id"
        }
    ]
}

# Via Pixel

This will define an amp-pixel (opens new window). The implementation can be found at Tenants/vhosts/marfeel/themes/default/tracker/customMetricPixel.jsp.

{
    "custom": [
        {
            "type": "pixel",
            "pixelSrc": "https://example.pixel.com",
        }
    ]
}

# Core metric extension

To add a metric provider that Marfeel does not support, new Metrics extension can be created by following these steps:

  1. Create the entity in Gutenberg/MarfeelWonderlandDomain/src/main/java/com/marfeel/wonderland/entity/metrics/
  2. Add the entity to Gutenberg/MarfeelWonderlandDomain/src/main/java/com/marfeel/wonderland/entity/metrics/Metrics.java
  3. Add the JS implementation for TOUCH in MarfeelXP/Dixie/src/js/marfeel/touch/features/metrics/
  4. Add the JSP implementation for AMP in MarfeelXP/Tenants/vhosts/marfeel/themes/default/tracker/
  5. Export the new entity in MarfeelXP/Dixie/src/js/marfeel/touch/dynamicLoaders/metrics/constants/filenames.js
  6. Add the json schema (opens new window) to MarfeelCodingStandards/json-lint/schemas/metrics/providers/

Deploying order

Gutenberg needs to be shuttled before you use this Metrics extension in the Tenant's repository.

# Metrics Implementation examples