You are here

function uc_googleanalytics_footer in Ubercart 5

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

Implementation of hook_footer().

File

uc_googleanalytics/uc_googleanalytics.module, line 17
Adds the required HTML and Javascript to the checkout complete 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 we can load the order...
    if ($order = uc_order_load($_SESSION['uc_googleanalytics_order_id'])) {

      // Check for which GA version is being used.
      if (variable_get('googleanalytics_legacy_version', TRUE)) {

        // Add the legacy script.
        $output = _uc_googleanalytics_ecommerce_legacy_script($order);
        uc_add_js('$(document).ready(function() { __utmSetTrans(); });', 'inline', 'footer');
      }
      else {

        // Add the updated script.
        $output = _uc_googleanalytics_ecommerce_script($order);
      }
    }

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