Skip to content

Commit fc8500c

Browse files
authored
Add alert container tracking for link analytics (#56209)
1 parent 69625e0 commit fc8500c

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

src/content-render/tests/render-content.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,18 @@ var a = 1
243243
expect(el.data('clipboard')).toBe(2967273189)
244244
// Generates a murmurhash based ID that matches a <pre>
245245
})
246+
247+
test('renders alerts with data-container attribute for analytics', async () => {
248+
const template = nl(`
249+
> [!NOTE]
250+
> This is a note with a [link](https://example.com)
251+
`)
252+
const html = await renderContent(template, { alertTitles: { NOTE: 'Note' } })
253+
const $ = cheerio.load(html)
254+
const alertEl = $('.ghd-alert')
255+
expect(alertEl.length).toBe(1)
256+
expect(alertEl.attr('data-container')).toBe('alert')
257+
expect(alertEl.hasClass('ghd-alert-accent')).toBe(true)
258+
expect(alertEl.find('a[href="https://example.com"]').length).toBe(1)
259+
})
246260
})

src/content-render/unified/alerts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default function alerts({ alertTitles = {} }) {
3434
const alertType = alertTypes[getAlertKey(node).toUpperCase()]
3535
node.tagName = 'div'
3636
node.properties.className = 'ghd-alert ghd-alert-' + alertType.color
37+
node.properties.dataContainer = 'alert'
3738
node.children = [
3839
h(
3940
'p',

src/events/lib/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ const link = {
320320
'lead',
321321
'notifications',
322322
'article',
323+
'alert',
323324
'toc',
324325
'footer',
325326
'static',

src/frame/components/ui/Alert/Alert.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function Alert({ className, html, children, type = 'IMPORTANT' }: AlertPr
2525
return (
2626
<div
2727
data-testid="alert"
28+
data-container="alert"
2829
className={cx(className, styles.container, `ghd-alert ghd-alert-${alertTypes[type].color}`)}
2930
>
3031
<p className="ghd-alert-title">

0 commit comments

Comments
 (0)