Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mwpw 135027 aa tracking on accordion #350

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions acrobat/blocks/eventwrapper/eventwrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,32 @@ const CONVERSION_START = 'conversion-start';
// const UPSELL_DIS = 'upsell-displayed';
const FADE = 'review fade-in';

const changeAccordionAnalytics = (fragment, fragmentName, alloy) => {
const allButtons = fragment.querySelectorAll('button');
allButtons.forEach((button, index) => {
button.removeAttribute('daa-ll');
button.addEventListener('click', function() {
const text = this.textContent.trim();
const ctaNumber = index + 1;
const state = this.getAttribute('aria-expanded') === 'true' ? 'Expand' : 'Collapse';
alloy(fragmentName, state, ctaNumber, text);
});
});
};

export default function init(element) {
const faqFrag = element.querySelector("a[href*='faq'], div[data-path*='faq']");
if (faqFrag) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TsayAdobe , can you help me ? I tried to write a test for this part of the code that I added, but the code inside setInterval isn't executed by the tests. When I call the init function from eventwrapper, that is imported inside the tests, setInterval is skipped and because of that I can not test changeAccordionAnalytics function. Can you please take a look ? Thanks.

const waitFragToLoad = setInterval(async () => {
const loadedFrag = element.querySelector("div[data-path*='faq'] .accordion-container");
if (loadedFrag) {
clearInterval(waitFragToLoad);
const { default: accordionAlloy } = await import('../../scripts/alloy/accordion.js');
changeAccordionAnalytics(loadedFrag, 'faq', accordionAlloy);
}
},100);
}

const wrapper = element;
const reviewBlock = document.querySelectorAll('.review');
const setCurrentEvent = (event) => {
Expand Down
30 changes: 30 additions & 0 deletions acrobat/scripts/alloy/accordion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export default function init(fragmentName, state, ctaNumber, text) {
const customLink = [fragmentName.toUpperCase(), state, `${ctaNumber}-${text}`].join('|');
const event = {
// always trigger the event using navigator.sendBeacon
documentUnloading: true,
data: {
eventType: 'web.webinteraction.linkClicks',
web: {
webInteraction: {
linkClicks: {
value: 1,
},
type: 'other',
name: customLink,
},
},
_adobe_corpnew: {
digitalData: {
primaryEvent: {
eventInfo: {
interaction: {[state]: customLink},
eventName: customLink,
},
},
},
},
},
};
window._satellite.track('event', event);
}
2 changes: 2 additions & 0 deletions acrobat/scripts/contentSecurityPolicy/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const connectSrc = [
'accounts.google.com/gsi/log',
'accounts.google.com/gsi/status',
'adobe.tt.omtrdc.net',
'adobedc.demdex.net/',
'adobeioruntime.net',
'analytics.tiktok.com',
'api.company-target.com/api/v2/',
Expand Down Expand Up @@ -162,6 +163,7 @@ const scriptSrc = [
'accounts.google.com/gsi/client',
'adobe.demdex.net',
'adobe.tt.omtrdc.net',
'adobedc.demdex.net/',
'analytics.tiktok.com/',
'analytics.twitter.com',
'assets.adobedtm.com',
Expand Down
36 changes: 36 additions & 0 deletions test/scripts/alloy/accordion.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { expect } from '@esm-bundle/chai';
import * as sinon from 'sinon';

const { default: init } = await import(
'../../../acrobat/scripts/alloy/accordion'
);

describe('Alloy accordion', () => {
beforeEach(() => {
window._satellite = {
track: sinon.stub(),
};
});

afterEach(() => {
sinon.restore();
});
[
['faq', 'Expand', 1, 'How do I fill out a form?'],
['faq', 'Expand', 3, 'How can I upload a photo of my signature?'],
['faq', 'Collapse', 1, 'How do I fill out a form?'],
['faq', 'Collapse', 3, 'How can I upload a photo of my signature?'],

].forEach(
([fragmentName, state, ctaNumber, text]) => {
it('initiates Alloy accordion', () => {
init(fragmentName, state, ctaNumber, text);
const customLink = [fragmentName.toUpperCase(), state, `${ctaNumber}-${text}`].join('|');
expect(
window._satellite.track.args[0][1].data._adobe_corpnew.digitalData
.primaryEvent.eventInfo.eventName
).to.include(customLink);
});
}
);
});
Loading