You are here

public function GTMContainer::genericCheck in GoogleTagManager 7.2

Determines whether to insert the snippet based on settings.

Parameters

string $type: The condition type.

Return value

bool TRUE if the conditions are met; FALSE otherwise.

1 call to GTMContainer::genericCheck()
GTMContainer::insertSnippet in includes/entity/container.inc
Determines whether to insert the snippet on the response.

File

includes/entity/container.inc, line 401

Class

GTMContainer
Defines the container configuration entity.

Code

public function genericCheck($type) {
  $this->toggle = "{$type}_toggle";
  $this->list = "{$type}_list";
  $this->context = "{$type}Context";
  $this->singular = $type;
  $toggle = $this
    ->get($this->toggle);
  if (empty($toggle)) {

    // Condition is not configured.
    return TRUE;
  }
  $values = $this
    ->get($this->list);
  $values = $values && is_array($values) ? array_filter($values) : $values;
  if (empty($values)) {
    $satisfied = $toggle == GOOGLE_TAG_EXCLUDE_LISTED;
  }
  else {
    $value = $this
      ->{$this->context}($values);
    if (is_string($values)) {

      // Examples: status and path.
      $satisfied = $value;
    }
    elseif (is_array($value)) {
      $satisfied = (bool) array_intersect($value, $values);
    }
    else {
      $satisfied = in_array($value, $values);
    }
    $satisfied = $toggle == GOOGLE_TAG_EXCLUDE_LISTED ? !$satisfied : $satisfied;
  }
  $this
    ->displayMessage('@singular check @satisfied', array(
    '@singular' => $this->singular,
    '@satisfied' => $satisfied,
  ));
  return $satisfied;
}