Weight is not preserved when saving multiple tags within the same container

Created on 19 August 2024, 4 months ago

Problem/Motivation

Containers support multiple tags, and the form presents the ability to order tags by weight. However, the weight is not respected when saving the form. The tags are always saved in the original order as they were rendered on the form.

The first tag is what the module considers the default tag and is loaded first via https://www.googletagmanager.com/gtag/js?id=DEFAULT_TAG_ID. Additionally tags are then registered as needed, but it's this first tag that's passed to the initial gtag script from Google.

So, does the order really matter?

In one case, I found it does. I maintain a platform of sites where we have a global GA4 tracker registered, and then a site-specific tracker. Many of the sites are still using an old UA- site-specific tracker. Google auto-created GA4 properties for the UA properties and auto-associated the GA4 property with them. gtag is supposed to load this GA4 tag automatically when you register the UA tag with gtag on a page. On this particular site, if the UA- tracker was not the first/default tracker, this didn't occur. I have no idea why. Other sites, it worked fine if the UA- tracker was not the default. Probably something about the tag configuration.

In any case, the weights should be respected on this form.

Steps to reproduce

  • Create a container and add multiple tags, one a G- tag and one a UA- tag.
  • Try and re-order the tags and save. Observe that the re-ordering has no effect.
  • Observe that the first tag listed is always the tag that's provided as the "id" query string to https://www.googletagmanager.com/gtag/js?id=

Proposed resolution

The tag IDs need to be sorted by weight before being saved to the container entity.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

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

Merge Requests

Comments & Activities

  • Issue created by @bkosborne
  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA
  • Status changed to Needs review 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    Okay, pushed an MR. However, the test needs a bit of work. The test today isn't testing much. It's passing 3 tags to the form to save, but in reality, only the first one is being processed by Drupal. This seems to be a problem with how the form request is being simulated with Request::create(), which is passing the form params as query strings and they aren't being processed into the request object in the same way that Drupal does with Request::createFromGlobals().

    In any case, if that were be resolved, the test modifications should pass.

  • Pipeline finished with Failed
    4 months ago
    Total: 610s
    #258466
  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA
Production build 0.71.5 2024