- Issue created by @Amber Himes Matz
- πΊπΈUnited States phenaproxima Massachusetts
Validation can be extremely tricky for recipe inputs, because the default value has to fulfill the constraints too. Unfortunately, something like Google Tag really doesn't have a valid default value. Additionally, recipes don't support input transformation. We could validate that the tag ID doesn't contain whitespace (an empty string would still pass that constraint), but we probably can't actively strip it out.
- πΊπΈUnited States Amber Himes Matz Portland, OR USA
My perspective is from the documentation writer's point of view. To have to say, "Make sure you don't have any leading or trailing spaces when you enter your GTM ID" in documentation for setting up analytics is weird to me. That just smacks of a programmer's problem, not a user's problem.
Since the Google Tag module is responsible for constructing the string for the script tag's src attribute, maybe this issue would be better filed in their queue instead. And instead of suggestion validation, suggesting trimming leading/trailing whitespace from the
tagId
variable.web/modules/contrib/google_tag/js/gtm.js, lines 23-30:
config.tagIds.forEach(function (tagId) { const script = document.createElement('script'); script.async = true; const dLink = dl != 'dataLayer' ? `&l=${dl}` : ''; script.src = `https://www.googletagmanager.com/gtm.js?id=${tagId}${gtm_environment}${dLink}`; script.type = 'text/javascript'; document.getElementsByTagName('head')[0].appendChild(script); });
@phenaproxima Ok with me to close as won't fix and I'll file it in the Google Tag module's queue instead.
- πΊπΈUnited States phenaproxima Massachusetts
Sure, that sounds good. We could also just repurpose this issue and move it to Google Tag's queue, so they have the context for why we're doing this.
- πΊπΈUnited States Amber Himes Matz Portland, OR USA
Updated title and issue summary.
I'm not sure how to move this to another project's queue. Could use some help with that.
- πΊπΈUnited States phenaproxima Massachusetts
Fixed. :) The "Project" field in the issue metadata is where you control that.
- πΊπΈUnited States Amber Himes Matz Portland, OR USA
Thanks! I just saw that a moment too late.
- πͺπΈSpain penyaskito Seville π, Spain πͺπΈ, UTC+2 πͺπΊ
Maybe this could happen on preSave instead of the rendering?
Actually, the recipe validates with:
Regex: '/^(?:GT|UA|G|AW|DC|GTM)-[0-9a-zA-Z]{4,}(?:-[0-9]{1,})?$/'
Wouldn't that be enough?
- πͺπΈSpain penyaskito Seville π, Spain πͺπΈ, UTC+2 πͺπΊ
Even if we still want this fixed in Google Tag, this would alleviate the issue on the Drupal CMS recipe with HTML5 validation:
form: '#type': 'textfield' '#title': 'Google Tag ID' + '#pattern': '/^(?:GT|UA|G|AW|DC|GTM)-[0-9a-zA-Z]{4,}(?:-[0-9]{1,})?$/' '#description': "The Google Tag ID for tracking. This ID is unique to each site you want to track separately, and must be in the form of GT-xxxxxx, G-xxxxxxxx, AW-xxxxxxxxx, GTM-xxxxxxxx or DC-xxxxxxxx."