# All files / composer/utils Metrics.js

0% Statements 0/6
0% Branches 0/2
0% Functions 0/1
0% Lines 0/5

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30

     /**
     * Thin wrapper around @bufferapp/buffer-js-metrics that automatically provides the app environment
     */

    import AppStore from '../stores/AppStore';
    import { AppEnvironments } from '../AppConstants';
    import BufferMetrics, { AppEnvironments as BufferMetricsAppEnvironments }
      from '@bufferapp/buffer-js-metrics';

    class Metrics extends BufferMetrics {
      static trackAction(...args) {
        const { appEnvironment, disableTelemetry } = AppStore.getMetaData();

        if (disableTelemetry) return undefined;

        // Map app env constants with BufferMetrics's internal app env constants
        const appEnvironmentsMap = new Map([
          [AppEnvironments.EXTENSION, BufferMetricsAppEnvironments.EXTENSION],
          [AppEnvironments.WEB_DASHBOARD, BufferMetricsAppEnvironments.WEB_DASHBOARD],
          [AppEnvironments.ONBOARDING, BufferMetricsAppEnvironments.ONBOARDING],
        ]);

        const bufferMetricsAppEnv = appEnvironmentsMap.get(appEnvironment);

        return BufferMetrics.trackAction(bufferMetricsAppEnv, ...args);
      }
    }

    export default Metrics;