You are here

function ga_push_push_key_mapper in GA Push 7

Same name and namespace in other branches
  1. 8 ga_push.module \ga_push_push_key_mapper()

Helper function to asign data to keys.

Only key_map keys will be mapped.

Parameters

array $key_map: Array with keys to translate.

array $data: Data push array.

bool $initialize_empty: Initialize empty values.

Return value

array Mapped data.

1 call to ga_push_push_key_mapper()
ga_push_method_ga_js_push in inc/ga_push.ga_js.inc
Send the ga push to JS on page load.

File

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

Code

function ga_push_push_key_mapper($key_map, $data, $initialize_empty = FALSE) {
  $mapped_data = array();
  foreach ($key_map as $key => $target) {
    $key = str_replace(array(
      'dimension',
      'metric',
    ), array(
      'cd',
      'cm',
    ), $mkey);
    if (isset($data[$key])) {
      $mapped_data[$target] = $data[$key];
    }
    elseif ($initialize_empty) {
      $mapped_data[$target] = '';
    }
  }
  return $mapped_data;
}