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
- class \Drupal\analytics\Render\AnalyticsJsMarkup implements \Drupal\analytics\Render\Countable, MarkupInterface uses MarkupTrait
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\RenderView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AnalyticsJsMarkup:: |
static | property | ||
AnalyticsJsMarkup:: |
public static | function |
inheritdoc} Overrides MarkupTrait:: |
|
AnalyticsJsMarkup:: |
public static | function | Checks if the Do Not Track protection is enabled. | |
MarkupTrait:: |
protected | property | The safe string. | |
MarkupTrait:: |
public | function | Returns the string length. | |
MarkupTrait:: |
public | function | Returns a representation of the object for use in JSON serialization. | |
MarkupTrait:: |
public | function | Returns the string version of the Markup object. |