You are here

abstract class CommerceGoogleTagManagerBaseAction in Commerce Google Tag Manager 7.2

@file This file contains the base class for CommerceGoogleTagManager actions.

Hierarchy

Expanded class hierarchy of CommerceGoogleTagManagerBaseAction

File

includes/CommerceGoogleTagManagerBaseAction.php, line 7
This file contains the base class for CommerceGoogleTagManager actions.

View source
abstract class CommerceGoogleTagManagerBaseAction extends RulesActionHandlerBase {

  /**
   * Returns the commerce event's name to be sent.
   *
   * @return string
   */
  public abstract function getCommerceEventName();

  /**
   * Get the default Rule's info.
   *
   * @return array
   */
  protected static function getDefaultsInfo() {
    return array(
      'group' => t('Commerce Google-TagManager'),
      'name' => get_called_class(),
    );
  }

  /**
   * Builds and pushes the current commerce data.
   *
   * @param array $commerceData
   */
  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) . ');';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommerceGoogleTagManagerBaseAction::getCommerceEventName abstract public function Returns the commerce event's name to be sent. 4
CommerceGoogleTagManagerBaseAction::getDefaultsInfo protected static function Get the default Rule's info.
CommerceGoogleTagManagerBaseAction::pushCommerceData protected function Builds and pushes the current commerce data.
RulesPluginHandlerBase::$element protected property
RulesPluginHandlerBase::access public function Implements RulesPluginImplInterface::access(). Overrides RulesPluginHandlerInterface::access
RulesPluginHandlerBase::assertions public function Returns an array of info assertions for the specified parameters. Overrides RulesPluginHandlerInterface::assertions 1
RulesPluginHandlerBase::dependencies public function Returns an array of required modules. Overrides RulesPluginHandlerInterface::dependencies
RulesPluginHandlerBase::form_alter public function Alters the generated configuration form of the element. Overrides RulesPluginHandlerInterface::form_alter
RulesPluginHandlerBase::info_alter public function Allows altering of the element's action/condition info. Overrides RulesPluginHandlerInterface::info_alter
RulesPluginHandlerBase::process public function Processes settings independent from a form submission. Overrides RulesPluginHandlerInterface::process
RulesPluginHandlerBase::validate public function Validates $settings independent from a form submission. Overrides RulesPluginHandlerInterface::validate
RulesPluginHandlerBase::__construct public function Overridden to provide $this->element to make the code more meaningful.