You are here

function ga_push_analyticsjs_measurement_protocol_mapping in GA Push 8

Same name and namespace in other branches
  1. 7 ga_push.module \ga_push_analyticsjs_measurement_protocol_mapping()

Translates Analytics.js keys to UTMP keys.

Push array data uses Analytics.js keys to name each param. UTMP uses another set of keys. This method translates those keys.

Parameters

array $data: Array with keys to be translated.

Return value

array Array with keys translated.

5 calls to ga_push_analyticsjs_measurement_protocol_mapping()
ga_push_method_php_utmp_construct_event_request_data in inc/ga_push.utmp.php.inc
Returns data array for a event tacking.
ga_push_method_php_utmp_construct_exception_request_data in inc/ga_push.utmp.php.inc
Returns data array for a exception tracking.
ga_push_method_php_utmp_construct_pageview_request_data in inc/ga_push.utmp.php.inc
Returns data array for a pageview tracking.
ga_push_method_php_utmp_construct_social_request_data in inc/ga_push.utmp.php.inc
Returns data array for a social tracking.
ga_push_method_utmp_php_construct_ecommerce_request_data in inc/ga_push.utmp.php.inc
Returns data arrays for a eCommerce tacking.

File

./ga_push.module, line 816
Drupal Module: GA Push.

Code

function ga_push_analyticsjs_measurement_protocol_mapping(array $data) {
  $map = ga_push_analyticsjs_measurement_protocol_map();
  $data_mapped = [];
  foreach ($data as $key => $value) {
    $mkey = isset($map[$key]) ? $map[$key] : $key;

    // Replace custom dimensions and metrics that uses Analytics.js
    // keys with UTMP keys.
    $mkey = str_replace([
      'dimension',
      'metric',
    ], [
      'cd',
      'cm',
    ], $mkey);
    $data_mapped[$mkey] = $value;
  }
  return $data_mapped;
}