Skip to content

Commit

Permalink
Add tracking attributes to links in card block (#1003)
Browse files Browse the repository at this point in the history
Co-authored-by: Ruchika Sinha <tek10248@Ruchikas-MacBook-Pro.local>
  • Loading branch information
Ruchika4 and Ruchika Sinha authored Jul 26, 2023
1 parent b5658ae commit ac3d423
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libs/blocks/card/card.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { decorateButtons } from '../../utils/decorate.js';
import { loadStyle, getConfig, createTag } from '../../utils/utils.js';
import { getMetadata } from '../section-metadata/section-metadata.js';
import { decorateLinkAnalytics } from '../../martech/attributes.js';

const HALF = 'OneHalfCard';
const HALF_HEIGHT = 'HalfHeightCard';
Expand Down Expand Up @@ -115,6 +116,8 @@ const addFooter = (links, container, merch) => {
};

const init = (el) => {
const headings = el.querySelectorAll('h1, h2, h3, h4, h5, h6');
decorateLinkAnalytics(el, headings);
const { miloLibs, codeRoot } = getConfig();
const base = miloLibs || codeRoot;
loadStyle(`${base}/deps/caas.css`);
Expand Down
19 changes: 19 additions & 0 deletions test/blocks/card/card.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,23 @@ describe('Card', () => {
expect(document.querySelector('.consonant-CardsGrid--2up')).to.exist;
});
});

describe('Analytics', () => {
before(async () => {
document.body.innerHTML = await readFile({ path: './mocks/two-up-cards.html' });
});

it('Analytics attribute are added to the links and headings in the card', () => {
const card = document.querySelector('.card');
init(card);
const links = card.querySelectorAll('a');
const headings = card.querySelectorAll('h1, h2, h3, h4, h5, h6');
links.forEach((link) => {
expect(link.hasAttribute('daa-ll'));
});
headings.forEach((heading) => {
expect(heading.hasAttribute('daa-lh'));
});
});
});
});

0 comments on commit ac3d423

Please sign in to comment.