You are here

function hook_ucga_display in Ubercart 8.4

Same name and namespace in other branches
  1. 6.2 docs/hooks.php \hook_ucga_display()
  2. 7.3 uc_googleanalytics/uc_googleanalytics.api.php \hook_ucga_display()

Determines whether e-commerce tracking code should be added to the page.

The Google Analytics module takes care of adding the necessary .js file from Google for tracking general statistics. The UC Google Analytics module works in conjunction with this code to add e-commerce specific code. However, the e-commerce code should only be added on appropriate pages. Generally, the correct page will be the checkout completion page at cart/checkout/complete. However, because modules can change the checkout flow as necessary, it must be possible for alternate pages to be used.

This hook allows other modules to tell the UC Google Analytics module that it should go ahead and add the e-commerce tracking code to the current page. A module simply needs to implement this hook and return TRUE on the proper order completion page to let UC Google Analytics know it should add the e-commerce tracking code to the current page.

The implementation below comes from the 2Checkout.com module which uses an alternate checkout completion page.

Return value

bool TRUE if e-commerce tracking code should be added to the current page.

1 function implements hook_ucga_display()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

uc_2checkout_ucga_display in payment/uc_2checkout/uc_2checkout.module
Implements hook_ucga_display().
1 invocation of hook_ucga_display()
uc_googleanalytics_display in uc_googleanalytics/uc_googleanalytics.module
Determines whether or not to display the e-commerce related JS through GA.

File

uc_googleanalytics/uc_googleanalytics.api.php, line 39
Hooks provided by the Google Analytics for Ubercart module.

Code

function hook_ucga_display() {

  // Tell UC Google Analytics to display the e-commerce JS on the custom
  // order completion page for this module.
  $route_match = \Drupal::routeMatch();
  if ($route_match
    ->getRouteName() == 'uc_2checkout.complete') {
    return TRUE;
  }
}