You are here

public function GTMContainer::fileTag in GoogleTagManager 7.2

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. [not used]

File

includes/entity/container.inc, line 534

Class

GTMContainer
Defines the container configuration entity.

Code

public function fileTag($type, $weight) {
  $uri = $this
    ->snippetURI($type);

  // file_create_url() is invoked in the JS render workflow.
  $url = file_create_url($uri);
  $query_string = variable_get('css_js_query_string', '');

  // This omits the query string, but drupal adds it.
  // This outputs defer="defer"; see drupal_get_js()
  drupal_add_js($url, array(
    'group' => JS_LIBRARY * 2,
    'requires_jquery' => FALSE,
    'defer' => TRUE,
  ));

  // This approach uses weight only but does not group the script tags so
  // difficult to put this at or near top of them.
  // This approach does not allow 'requires_jquery' to be set.
  // Needs the '#value' key to get a closing tag with theme_html_tag().
  // This outputs defer="1"
  // drupal_add_html_head($attachment[0], $attachment[1]);
  $attachment = array(
    array(
      '#type' => 'html_tag',
      '#tag' => 'script',
      '#attributes' => array(
        'type' => 'text/javascript',
        'src' => $url . '?' . $query_string,
        'defer' => TRUE,
      ),
      '#weight' => $weight,
      '#value' => '',
    ),
    "google_tag_{$type}_tag__{$this->id()}",
  );
  return $attachment;
}