You are here

function uc_googleanalytics_footer in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_googleanalytics/uc_googleanalytics.module \uc_googleanalytics_footer()

Implements hook_footer().

File

uc_googleanalytics/uc_googleanalytics.module, line 28
Adds the required Javascript to the checkout completion page to allow e-commerce statistics tracking through Google Analytics.

Code

function uc_googleanalytics_footer($main = 0) {

  // 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, 'inline', 'footer');
    }

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