public function SnippetBuilder::pageAttachment in Hotjar 8
Same name and namespace in other branches
- 8.2 src/SnippetBuilder.php \Drupal\hotjar\SnippetBuilder::pageAttachment()
Implements hook_page_attachment().
Overrides SnippetBuilderInterface::pageAttachment
File
- src/
SnippetBuilder.php, line 114
Class
- SnippetBuilder
- Class SnippetBuilder.
Namespace
Drupal\hotjarCode
public function pageAttachment(array &$attachments) {
$uri = 'public://hotjar/hotjar.script.js';
$query_string = $this->state
->get('system.css_js_query_string') ?: '0';
$query_string_separator = strpos($uri, '?') !== FALSE ? '&' : '?';
$url = file_url_transform_relative(file_create_url($uri));
$attachments['#attached']['html_head'][] = [
[
'#type' => 'html_tag',
'#tag' => 'script',
'#attributes' => [
'src' => $url . $query_string_separator . $query_string,
],
],
'hotjar_script_tag',
];
}