You are here

class Create in Googalytics - Google Analytics 8

Class Create.

Hierarchy

Expanded class hierarchy of Create

2 files declare their use of Create
CreateTest.php in tests/src/Unit/AnalyticsCommand/CreateTest.php
DefaultCommandSubscriber.php in src/EventSubscriber/DefaultCommandSubscriber.php

File

src/AnalyticsCommand/Create.php, line 8

Namespace

Drupal\ga\AnalyticsCommand
View source
class Create extends Generic {
  const DEFAULT_PRIORITY = 300;

  /**
   * The Google Analytics property ID.
   *
   * @var string
   */
  protected $trackingId;

  /**
   * The analytics cookie domain.
   *
   * @var string
   */
  protected $cookieDomain;

  /**
   * Create constructor.
   *
   * @param string $tracking_id
   *   A Google Analytics property ID.
   * @param string $cookie_domain
   *   The cookie domain.
   * @param string $tracker_name
   *   The tracker name.
   * @param array $fields_object
   *   A set of additional options for the command.
   * @param int $priority
   *   The command priority.
   */
  public function __construct($tracking_id, $cookie_domain = 'auto', $tracker_name = NULL, array $fields_object = [], $priority = self::DEFAULT_PRIORITY) {
    parent::__construct('create', $fields_object, $tracker_name, $priority);
    $this->trackingId = $tracking_id;
    $this->cookieDomain = $cookie_domain;
  }

  /**
   * Get the tracking id.
   *
   * @return string
   *   The tracking id.
   */
  public function getTrackingId() {
    return $this->trackingId;
  }

  /**
   * Get the cookie domain.
   *
   * @return string
   *   The cookie domain.
   */
  public function getCookieDomain() {
    return $this->cookieDomain;
  }

  /**
   * {@inheritdoc}
   */
  public function getSettingCommands() {
    $command = [
      $this->command,
      $this->trackingId,
      $this->cookieDomain,
    ];
    if (!empty($this->trackerName)) {
      $command[] = $this->trackerName;
    }
    if (!empty($this->fieldsObject)) {
      $command[] = $this->fieldsObject;
    }
    return [
      $command,
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Create::$cookieDomain protected property The analytics cookie domain.
Create::$trackingId protected property The Google Analytics property ID.
Create::DEFAULT_PRIORITY constant Overrides Generic::DEFAULT_PRIORITY
Create::getCookieDomain public function Get the cookie domain.
Create::getSettingCommands public function An array of commands to be sent to Google Analytics. Overrides Generic::getSettingCommands
Create::getTrackingId public function Get the tracking id.
Create::__construct public function Create constructor. Overrides Generic::__construct
DrupalSettingCommandsTrait::$priority protected property Priority integer.
DrupalSettingCommandsTrait::getPriority public function An integer value for sorting by priority.
Generic::$command protected property The command name.
Generic::$fieldsObject protected property A map of values for the command's fieldsObject parameter.
Generic::$trackerName protected property The name of the tracker for this command.
Generic::getCommand public function Get the command name.
Generic::getFieldsObject public function Get the map of values for the command's fieldsObject parameter.
Generic::getTrackerName public function The tracker this command will be applied to, if specified.