You are here

function ga_push_browser_init in GA Push 7

Implements hook_init().

File

modules/browser/ga_push_browser.module, line 12
Drupal Module: GA Push (browser).

Code

function ga_push_browser_init() {

  // @TODO: Use Context to add the GA Push Browser Events JS code.
  $query = new EntityFieldQuery();
  $result = $query
    ->entityCondition('entity_type', 'ga_push_browser_event')
    ->propertyCondition('status', 1)
    ->execute();
  $gapb_events = array();
  if (isset($result['ga_push_browser_event'])) {
    $gapb_events_nids = array_keys($result['ga_push_browser_event']);
    $gapb_events = ga_push_browser_event_load_multiple($gapb_events_nids);
    foreach ($gapb_events as $gapb_event) {
      $jsoptions[] = array(
        'selector' => $gapb_event->selector,
        'push' => array(
          $gapb_event->ga_category,
          $gapb_event->ga_action,
          $gapb_event->ga_label,
          $gapb_event->ga_value,
        ),
        'bind' => $gapb_event->bind,
      );
    }
    drupal_add_js(array(
      'ga_push_browser' => $jsoptions,
    ), 'setting');
  }
}