- Issue created by @enchufe
- Merge request !2Issue #3439064: Add custom attributes to scripts in order to have more control over their execution. β (Merged) created by enchufe
- Status changed to Needs review
9 months ago 3:46pm 6 April 2024 - πͺπΈSpain enchufe Spain
Removed the "required" property from the new field in the configuration form.
- π³π΅Nepal sujan shrestha Nepalπ³π΅, Kathmandu
sujan shrestha β made their first commit to this issueβs fork.
-
sujan shrestha β
committed 170f6d71 on 1.1.x authored by
enchufe β
Issue #3439064 by enchufe: Add custom attributes to scripts in order to...
-
sujan shrestha β
committed 170f6d71 on 1.1.x authored by
enchufe β
- π³π΅Nepal sujan shrestha Nepalπ³π΅, Kathmandu
Hi @enchufe, thank you for the new feature request and for providing the patch for 'custom attributes to scripts' feature.
I have implemented the
Xss::filter()
function to properly sanitized before using raw to output the$script_attributes
value. Here's how it's applied on the module file:$script_attributes = Xss::filter($script_attributes);
Additionally, I've utilized the 'raw' filter like
{{ script_attributes|raw }}
on the twig file to display the HTML-encoded script attributes. For example, type="text/plain" data-category="analytics" was displayed as show on the attachment screenshot. - πͺπΈSpain enchufe Spain
If attributes are added in TWIG as raw, they are not displayed in the final HTML, and the
async
attribute is displayed asasync="true"
.Source: drupal/ga4_google_analytics:dev-1.1.x
- π¨πSwitzerland florianmuellerch Aarau, Switzerland
@enchufe thanks for the issue, was looking for this!
How do you solve the delayed loading of any given script provided by a module (when consent was not yet given), simply by its attributes? Any hook I don't know of yet? - πͺπΈSpain enchufe Spain
@florianmuellerCH To manage Cookies I use the JavaScript library orestbida/cookieconsent. The GA4 beacon is loaded with the attributes
type=text/plain data-category=analytics
. And the rest is configured by the library by activating the script (removingtype=text/plain
) when consenting to Cookies.
This gave me quite a headache, I hope it helps! - Status changed to RTBC
8 months ago 1:12am 2 May 2024 - π¨πSwitzerland florianmuellerch Aarau, Switzerland
@enchufe that is simply pure gold, thank you so much! You saved me a loooot of headache!
And for the issue, I now use the dev branch and the change works absolutely fine, so I think it could be released. Could this be closed, or RTBC?
- Status changed to Fixed
6 months ago 3:58am 19 June 2024 Automatically closed - issue fixed for 2 weeks with no activity.