Skip to content

Commit

Permalink
Revert "[MWPW-152968] mWeb - Passing ECID to Branch.io banner - Imple…
Browse files Browse the repository at this point in the history
…mentation" (#2612)

Revert "[MWPW-152968] mWeb - Passing ECID to Branch.io banner - Implementatio…"

This reverts commit 6943446.
  • Loading branch information
drashti1712 authored Jul 24, 2024
1 parent 4d3ab7b commit 3afac8d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 55 deletions.
24 changes: 2 additions & 22 deletions libs/blocks/mobile-app-banner/mobile-app-banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,8 @@ async function getKey(product) {
return keyMatch[0]?.key;
}

async function getECID() {
let ecid = null;
if (window.alloy) {
await window.alloy('getIdentity').then((data) => {
ecid = data?.identity?.ECID;
}).catch((err) => window.lana.log(`Error fetching ECID: ${err}`, { tags: 'errorType=error,module=mobile-app-banner' }));
}
return ecid;
}

/* eslint-disable */
function branchInit(key, ecidVal) {
function branchInit(key) {
let initValue = false;
function initBranch() {
if (initValue) {
Expand Down Expand Up @@ -58,16 +48,8 @@ function branchInit(key, ecidVal) {
0
);
const privacyConsent = window.adobePrivacy?.hasUserProvidedConsent();
const isAndroid = navigator.userAgent.includes('Android');

const cookieGrp = window.adobePrivacy?.activeCookieGroups();
const performanceCookieConsent = cookieGrp.includes('C0002');
const advertisingCookieConsent = cookieGrp.includes('C0004');

if (performanceCookieConsent && advertisingCookieConsent && isAndroid) branch.setBranchViewData({ data: { ecid: ecidVal }});
branch.init(key, { tracking_disabled: !privacyConsent });
}

['adobePrivacy:PrivacyConsent', 'adobePrivacy:PrivacyReject', 'adobePrivacy:PrivacyCustom']
.forEach((event) => {
window.addEventListener(event, initBranch);
Expand All @@ -81,7 +63,5 @@ export default async function init(el) {
const classListArray = Array.from(el.classList);
const product = classListArray.find((token) => token.startsWith('product-')).split('-')[1];
const key = await getKey(product);
if (!key) return;
const ecid = await getECID();
branchInit(key, ecid);
if (key) branchInit(key);
}
34 changes: 1 addition & 33 deletions test/blocks/mobile-app-banner/mobile-app-banner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ describe('mobile-app-banner', () => {
});

it('should init by adding branchio script', async () => {
window.adobePrivacy = {
hasUserProvidedConsent: () => true,
activeCookieGroups: () => ['C0002', 'C0004'],
};
const userAgentStub = sinon.stub(navigator, 'userAgent').get(() => 'Android');
window.adobePrivacy = { hasUserProvidedConsent: () => true };
const module = await import('../../../libs/blocks/mobile-app-banner/mobile-app-banner.js');
const banner = document.body.querySelector('.mobile-app-banner.product-test');
await module.default(banner);
Expand All @@ -67,33 +63,5 @@ describe('mobile-app-banner', () => {
if (scriptTag.getAttribute('src') !== null) scriptSrcs.push(scriptTag.getAttribute('src'));
});
expect(scriptSrcs).to.include('https://cdn.branch.io/branch-latest.min.js');
userAgentStub.restore();
});

it('should fetch ecid from alloy and return if event is dispatched twice', async () => {
window.adobePrivacy = {
hasUserProvidedConsent: () => true,
activeCookieGroups: () => ['C0002', 'C0004'],
};
window.alloy = () => {};
const alloyStub = sinon.stub(window, 'alloy').callsFake((command) => {
if (command === 'getIdentity') {
return Promise.resolve({ identity: { ECID: 'test-ecid' } });
}
return 'test-ecid';
});
const module = await import('../../../libs/blocks/mobile-app-banner/mobile-app-banner.js');
const banner = document.body.querySelector('.mobile-app-banner.product-test');
await module.default(banner);
window.dispatchEvent(new CustomEvent('adobePrivacy:PrivacyConsent'));
await delay(0);
const scriptTags = document.querySelectorAll('head > script');
const scriptSrcs = [];
scriptTags.forEach((scriptTag) => {
if (scriptTag.getAttribute('src') !== null) scriptSrcs.push(scriptTag.getAttribute('src'));
});
window.dispatchEvent(new CustomEvent('adobePrivacy:PrivacyConsent'));
expect(scriptSrcs).to.include('https://cdn.branch.io/branch-latest.min.js');
alloyStub.restore();
});
});

0 comments on commit 3afac8d

Please sign in to comment.