You are here

function ga_push_method_ssga in GA Push 7

GA Push Method callback: SSGA (php).

1 string reference to 'ga_push_method_ssga'
ga_push_ga_push_method in ./ga_push.module
Implements hook_ga_push_method().

File

inc/ga_push.ssga.inc, line 11
SSGA: method and functions

Code

function ga_push_method_ssga($push, $type, $options) {
  if (class_exists('ssga')) {
    $ga = new ssga();

    // Set your Google Analytics key:
    $id = !empty($options['tid']) ? $options['tid'] : variable_get('googleanalytics_account', '');
    $ga
      ->setAccountId($id);

    // Set your charset:
    $ga
      ->setCharset("UTF-8");

    // Set your hostname:
    // @TODO: domain integration.
    $ga
      ->setHostName($GLOBALS['base_url']);

    // Set language:
    $ga
      ->setLanguage($GLOBALS['language']->language);

    // Set an event based on:
    // http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html
    switch ($type) {
      case GA_PUSH_TYPE_EVENT:

        // Complete optional parameters:
        $push += array(
          'eventLabel' => '',
          'eventValue' => 1,
        );
        $ga
          ->setEvent($push['eventCategory'], $push['eventAction'], $push['eventLabel'], $push['eventValue']);
        break;
    }

    // Push the event.
    $ga
      ->create();
  }
  else {

    // @TODO: Throw an error
  }
}