dataLayer info is not outputting after update to 2.0.1

Created on 14 November 2023, about 1 year ago
Updated 22 November 2023, 12 months ago

It seems odd to me that no one would have reported this since August if it was really a bug, so I'm assuming this is user error on my end and putting it in as a support request. :)

While working through a Drupal 10 upgrade, I bumped my version of the dataLayer module to 2.0.1 (I was originally on 1.0). After doing so, the dataLayer output no longer appears in the head of my nodes. The same behavior occurs on 2.0.x-dev, but if I downgrade to 2.0.0, the output does appear as expected.

I've locked my Composer version dependency to 2.0.0 for now, but is there any indication as to why that might not be appearing for me? From some investigation, it seems as if the culprit was in 🐛 Pages are uncacheable because of the cache context user Fixed : if I add back lines 122–137 in the datalayer.module file, I once again see the dataLayer output in the head. I don't have a good enough understanding of the lazy builder discussion in that issue to know if that code snippet removal was intentionally made part of that commit, but if not, I'm happy to provide a merge request to bring it back (without the user cache context change that was the reason for the original issue).

Other items potentially of note:

If there's any more information I can provide to help troubleshoot, please let me know—thanks!

💬 Support request
Status

Active

Version

2.0

Component

Code

Created by

🇺🇸United States kurttrowbridge

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kurttrowbridge
  • 🇺🇸United States eojthebrave Minneapolis, MN

    That's definitely weird. It's outputting the tag for me, albeit at the bottom of the page. See 🐛 In HTML Datalayer output snippet is at wrong location before body closing Active . And the lazy builder should "just work". Which I'm sure makes this especially frustrating.

    I wonder if you've got another module installed that's somehow changing what happens in hook_page_bottom()? Like other modules that are trying to insert JS into the bottom of the page? Seems like a stretch ... but maybe.

    What theme are you using? If your theme overrides the html.html.twig template file can you confirm that it includes the {{ page_bottom }} variable? If that's missing than content added in hook_page_bottom() wouldn't be added to the page.

    And if it's not any of those things could you share the content of your datalayer config YAML file? That way I could try with the same configuration and see if it's something configuration related.

  • 🇺🇸United States kurttrowbridge

    Thanks for the quick reply! I had another chance to look further into this tonight, and unfortunately still don't have an answer. What I tried:

    • Switching the datalayer_page_bottom() hook to datalayer_page_top()
    • Uninstalling any other modules that implemented hook_page_bottom() (AMP, Mailchimp, Tour)
    • Removing my custom theme's html.html.twig template (even though it did have {{ page_bottom }} included)

    I've included my datalayer.settings.yml contents below.

    _core:
      default_config_hash: N67AkcKPlikWJbwxABv6MSMpGuXe36qWZfH88pEzeqc
    add_page_meta: true
    output_terms: true
    output_fields: true
    remove_from_admin_routes: false
    lib_helper: false
    entity_meta:
      created: '0'
      langcode: '0'
      name: '0'
      status: '0'
      uid: '0'
      uuid: '0'
      vid: '0'
    enable_ia: false
    ia_depth: 3
    ia_category_primary: primaryCategory
    ia_category_sub: subCategory
    vocabs:
      tags: tags
      column: '0'
    expose_user_details: ''
    expose_user_details_roles:
      authenticated: '0'
      content_editor: '0'
      social_media_editor: '0'
      administrator: '0'
    current_user_meta:
      name: '0'
      mail: '0'
      roles: '0'
      created: '0'
      access: '0'
    group: false
    expose_user_details_fields: false
    entity_title: entityTitle
    entity_type: entityType
    entity_bundle: entityBundle
    entity_identifier: entityId
    group_label: groupLabel
    drupal_language: drupalLanguage
    drupal_country: drupalCountry
    site_name: siteName
    key_replacements:
      - ''
    

    And it case it's relevant, the hook_datalayer_alter() implementation through which I handle multivalue fields and a couple custom additions:

    /**
     * Implements hook_datalayer_alter().
     */
    function bridge_utilities_datalayer_alter(&$data_layer) {
      // Modify data layer for Tags.
      if (isset($data_layer['entityTaxonomy']['tags'])) {
        $data_layer['articleTags'] = implode('|', $data_layer['entityTaxonomy']['tags']);
      }
    
      // Modify data layer for Authors.
      if (isset($data_layer['field_author'])) {
        $authors = $data_layer['field_author']['value'];
        $author_names = [];
        foreach ($authors as $author) {
          if (!empty($author['label'])) {
            $author_names[] = $author['label'];
          }
        }
        $data_layer['articleAuthors'] = implode('|', $author_names);
      }
    
      // Modify data layer for publish date.
      if (isset($data_layer['entityCreated'])) {
        $data_layer['articleDate'] = date('Y-m-d', $data_layer['entityCreated']);
      }
    
      // Modify data layer for donation confirmation order ID and revenue.
      if (\Drupal::request()->get('uid') !== NULL) {
        $data_layer['order_id'] = \Drupal::request()->get('uid');
      }
      if (\Drupal::request()->get('amount') !== NULL) {
        $data_layer['revenue'] = \Drupal::request()->get('amount');
      }
    }

    Thanks again!

Production build 0.71.5 2024