You are here

function ga_push_action_push_event in GA Push 7

Add a push event from a rules action.

File

./ga_push.rules.inc, line 203
Rules implementation.

Code

function ga_push_action_push_event($parameters) {
  $value = trim($parameters['value']);
  $push = array(
    'eventCategory' => $parameters['category'],
    'eventAction' => $parameters['action'],
    'eventLabel' => $parameters['label'],
    'eventValue' => strlen($value) ? (int) $value : NULL,
    'non-interaction' => (bool) $parameters['non-interaction'],
  );

  // Add event property only for datalayer.
  $default_method_key = variable_get('ga_push_default_method', GA_PUSH_METHOD_ANALYTICS_JS);
  if ($parameters['method'] == GA_PUSH_METHOD_DATALAYER_JS || $parameters['method'] == GA_PUSH_METHOD_DEFAULT && $default_method_key == GA_PUSH_METHOD_DATALAYER_JS) {
    $push['event'] = $parameters['event'];
  }
  ga_push_add_event($push, $parameters['method']);
}