Updated the event tagging for the AnalyticsEvent+Tagging extension in the Infrastructure package to support attribute-capable tags.

This commit is contained in:
2026-09-04 14:57:29 +02:00
parent a9a62e10df
commit a71edd37ab
3 changed files with 13 additions and 2 deletions
@@ -12,7 +12,7 @@ public extension Analytics.Event {
/// ```
///
/// - Returns: one HTML attribute per event attribute, applied verbatim.
func tagging<Tag: HTMLTrait.Attributes.Global>() -> [HTMLAttribute<Tag>] {
func tagging<Tag: MarkupTagDefinition & MarkupTrait.AllowsAttributes>() -> [HTMLAttribute<Tag>] {
attributes.map {
.custom(
name: $0.name,
@@ -46,4 +46,14 @@ struct AnalyticsEventTaggingTests {
#expect(attributes.count == event.attributes.count)
}
@Test
func `applies the event name to an SVG tag`() {
// `SVGTag.path` is no `HTMLTrait.Attributes.Global`, so this stops compiling if the method narrows back to HTML tags.
let rendered = SVG.path {}
.attributes(contentsOf: Analytics.Event(name: "logo").tagging())
.render()
#expect(rendered.contains(#"data-umami-event="logo""#))
}
}
@@ -17,6 +17,7 @@ struct StructuredDataTests {
name: "A Site",
url: "https://site.example/",
logo: "https://site.example/logo.png",
inLanguage: ["en", "nl"],
profiles: [
"https://social.example/a-site",
"https://videos.example/a-site",
@@ -26,7 +27,7 @@ struct StructuredDataTests {
#expect(data.payload == #"{"@context":"https://schema.org","@graph":["# +
#"{"@type":"Organization","@id":"https://site.example/#organization","name":"A Site","url":"https://site.example/","logo":"https://site.example/logo.png","# +
#""sameAs":["https://social.example/a-site","https://videos.example/a-site"]},"# +
#"{"@type":"WebSite","name":"A Site","url":"https://site.example/","publisher":{"@id":"https://site.example/#organization"}}]}"#
#"{"@type":"WebSite","name":"A Site","url":"https://site.example/","publisher":{"@id":"https://site.example/#organization"},"inLanguage":["en","nl"]}]}"#
)
}