You are here

function ga_push_push_key_mapper in GA Push 8

Same name and namespace in other branches
  1. 7 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 845
Drupal Module: GA Push.

Code

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