Can't save Google Tag ID

Created on 4 September 2025, 12 days ago

Problem/Motivation

On fresh install of the module.
When entering Google Tag ID or copy pasting ID into 'Google Tag ID(s)' and pressing on Save button there is error message and empty field without any explanation.

Steps to reproduce

Install the latest 2.x module.
Go to page /admin/config/services/google-tag.
Enter ID or copy paste it from Google Tag Manager or other source into the 'Google Tag ID(s)' field.
Scroll to the bottom of the settings form and press on the Save button.

The page is refreshed and we have Error message without details, empty field with red border.

I tried to debug and have found that those error is related to required field validation. So in such case on form validation step the field is treated as empty, but the value was entered before submit of the form.

It is the same behavior for correct and wrong codes.

Proposed resolution

I've found it doesn't happen when we trigger the 'change' event e.g. clicking somewhere outside the field after entering value and before pressing on the Save button.

If GTM-xxxxxxxx code was inputed there should be added additional fieldset by ajax with additional settings for the GTM ID in the Advanced settings section at the bottom of the form.

After this the form can be successfully saved.

If not correct ID is entered and we click outside the field - we don't see validation error under the field until we press on the Save button.

I've not found other solution than just removing ajax from the Google Tag ID field.

In this case I didn't notice mentioned bugs.
For incorrect ID you should see error under the field.
For correct ID the form submits and if it was GTM code you should see additional settings for those GTM ID in Advanced settings.

So there is some bug or come conflict with ajax and form validation.

I tried also to move the validation of the field from client side by removing '#pattern' in the code and adding backend validation for the field. But it didn't help. The validation function was run several times. First time there was value for the field and on second - the field's value was empty. I haven't found why yet....

So maybe it would be better just to disable ajax and update the description with additional message that the GTM advanced settings can be configured after adding and saving correct GTM code?

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.0

Component

User interface

Created by

🇺🇦Ukraine khiminrm

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024