protected function CommerceGoogleTagManagerBaseAction::pushCommerceData in Commerce Google Tag Manager 7.2
Builds and pushes the current commerce data.
Parameters
array $commerceData:
4 calls to CommerceGoogleTagManagerBaseAction::pushCommerceData()
- CommerceGoogleTagManagerActionAddToCart::execute in includes/
rules/ CommerceGoogleTagManagerActionAddToCart.php - Executes the action.
- CommerceGoogleTagManagerActionCheckout::execute in includes/
rules/ CommerceGoogleTagManagerActionCheckout.php - Executes the action.
- CommerceGoogleTagManagerActionPurchase::execute in includes/
rules/ CommerceGoogleTagManagerActionPurchase.php - Executes the action.
- CommerceGoogleTagManagerActionRemoveFromCart::execute in includes/
rules/ CommerceGoogleTagManagerActionRemoveFromCart.php - Executes the action.
File
- includes/
CommerceGoogleTagManagerBaseAction.php, line 33 - This file contains the base class for CommerceGoogleTagManager actions.
Class
- CommerceGoogleTagManagerBaseAction
- @file This file contains the base class for CommerceGoogleTagManager actions.
Code
protected function pushCommerceData(array $commerceData) {
$script = 'var dataLayer = dataLayer || []; ';
$data = array(
'event' => $this
->getCommerceEventName(),
'ecommerce' => $commerceData,
);
$context = array(
'event' => $this
->getCommerceEventName(),
);
// Allow other modules to alter this data before sending to DataLayer
drupal_alter('commerce_google_tag_manager_commmerce_data', $data, $context);
// Add the data line to the JS array.
$_SESSION['commerce_google_tag_manager'][] = $script . 'dataLayer.push(' . drupal_json_encode($data) . ');';
}