Problem/Motivation

In 8.x-1.x version of the google_tag module we have below service

\Drupal::service('google_tag.container_manager')->getScriptAttachments($variables);

do we have similar things in 2.x release of this module

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

nitesh624 created an issue. See original summary.

nitesh624’s picture

Issue summary: View changes
nitesh624’s picture

nitesh624’s picture

So my requirement is as below:
I have a media type named youtube_video and this media has a plain text field to capture youtube url and from manage display config i have configured this field to show as oEmbed content
Now this youtube url is rendered as an iframe and I want to inject the GTM script within this iframe

So when i doing research, I came across https://www.drupal.org/project/drupal/issues/3042383 issue and from https://www.drupal.org/project/drupal/issues/3042383#comment-14205901 i got below code snippet which is using \Drupal::service('google_tag.container_manager') service . but this service is no longer exists on 2.x version of google_tag module.

/**
 * Implements hook_preprocess_media_oembed_iframe().
 */
function YOUR_THEME_preprocess_media_oembed_iframe(array &$variables) {
  if ($variables['resource']->getProvider()->getName() === 'YouTube') {
    $variables['media'] = str_replace('?feature=oembed', '?feature=oembed&enablejsapi=1', (string) $variables['media']);
  }
  $variables['#attached']['html_response_attachment_placeholders']['scripts'] = '<js-placeholder token="' . $variables['placeholder_token'] . '">';
  $variables['#attached']['html_response_attachment_placeholders']['head'] = '<head-placeholder token="' . $variables['placeholder_token'] . '">';
  // Add GTM.
  \Drupal::service('google_tag.container_manager')->getScriptAttachments($variables);
}

Is there any way to achieve my requirement with 2.x version of google tag module?

nitesh624’s picture

Can anyone from the module maintainers help here?

nitesh624’s picture

hi is there any update here