You are here

function uc_googleanalytics_page_alter in Ubercart 7.3

Implements hook_page_alter().

File

uc_googleanalytics/uc_googleanalytics.module, line 31
Adds Google Analytics Javascript to the checkout completion page.

Code

function uc_googleanalytics_page_alter(&$page) {

  // Check to see if we are at the order completion page.
  if (uc_googleanalytics_display()) {

    // If so, then if we can load the order...
    if (!empty($_SESSION['ucga_order_id']) && ($order = uc_order_load($_SESSION['ucga_order_id']))) {

      // Build the GA tracking code.
      $script = uc_googleanalytics_ecommerce_js($order);

      // Add the code to the footer.
      drupal_add_js($script, array(
        'type' => 'inline',
        'scope' => 'footer',
        'preprocess' => FALSE,
      ));
    }

    // Clean out the session variable.
    if (isset($_SESSION['ucga_order_id'])) {
      unset($_SESSION['ucga_order_id']);
    }
  }
}