You are here

public function Container::fileTag in GoogleTagManager 8

Returns tag array for the snippet type.

Parameters

string $type: The snippet type.

int $weight: The weight of the item.

Return value

array The tag array.

File

src/Entity/Container.php, line 556

Class

Container
Defines the container configuration entity.

Namespace

Drupal\google_tag\Entity

Code

public function fileTag($type, $weight) {
  $uri = $this
    ->snippetURI($type);
  $url = file_url_transform_relative(file_create_url($uri));
  $query_string = \Drupal::state()
    ->get('system.css_js_query_string') ?: '0';
  $attachment = [
    [
      '#type' => 'html_tag',
      '#tag' => 'script',
      '#attributes' => [
        'src' => $url . '?' . $query_string,
        'defer' => TRUE,
      ],
      '#weight' => $weight,
    ],
    "google_tag_{$type}_tag__{$this->id()}",
  ];
  return $attachment;
}