You are here

final class AnalyticsJsMarkup in Analytics 8

Defines an object that passes safe strings through the render system.

This object should only be constructed with a known safe string. If there is any risk that the string contains user-entered data that has not been filtered first, it must not be used.

Hierarchy

Expanded class hierarchy of AnalyticsJsMarkup

1 file declares its use of AnalyticsJsMarkup
GoogleTagManager.php in src/Plugin/AnalyticsService/GoogleTagManager.php

File

src/Render/AnalyticsJsMarkup.php, line 15

Namespace

Drupal\analytics\Render
View source
final class AnalyticsJsMarkup implements MarkupInterface, \Countable {
  use MarkupTrait;

  /**
   * @var bool
   */
  static $isDntEnforced;

  /**
   * @{inheritdoc}
   */
  public static function create($string) {
    if ($string instanceof self) {
      return $string;
    }
    $string = (string) $string;
    if ($string === '') {
      return '';
    }
    if (static::isDntEnforced()) {
      $string = "if (!navigator.doNotTrack && !window.doNotTrack && !navigator.msDoNotTrack) {\n" . $string . "\n}";
    }
    $safe_string = new static();
    $safe_string->string = $string;
    return $safe_string;
  }

  /**
   * Checks if the Do Not Track protection is enabled.
   *
   * @return bool
   */
  public static function isDntEnforced() {
    if (!isset(static::$isDntEnforced)) {
      static::$isDntEnforced = \Drupal::config('analytics.settings')
        ->get('privacy.dnt');
    }
    return static::$isDntEnforced;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AnalyticsJsMarkup::$isDntEnforced static property
AnalyticsJsMarkup::create public static function inheritdoc} Overrides MarkupTrait::create
AnalyticsJsMarkup::isDntEnforced public static function Checks if the Do Not Track protection is enabled.
MarkupTrait::$string protected property The safe string.
MarkupTrait::count public function Returns the string length.
MarkupTrait::jsonSerialize public function Returns a representation of the object for use in JSON serialization.
MarkupTrait::__toString public function Returns the string version of the Markup object.