Skip to content

Commit

Permalink
Merge pull request #840 from adobecom/MWPW-159560
Browse files Browse the repository at this point in the history
MWPW-159560
  • Loading branch information
Blainegunn authored Oct 2, 2024
2 parents 6dc4450 + 504a98e commit 2422b33
Showing 1 changed file with 87 additions and 61 deletions.
148 changes: 87 additions & 61 deletions acrobat/scripts/alloy/verb-widget.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
const imsReady = setInterval(() => {
// eslint-disable-next-line no-underscore-dangle
if (window.adobeIMS?.getAccessToken) {
clearInterval(imsReady);
const imsIsReady = new CustomEvent('IMS:Ready:Unity');
window.dispatchEvent(imsIsReady);
}
}, 100);

function getSessionID() {
const aToken = window.adobeIMS.getAccessToken();
const arrayToken = aToken?.token.split('.');
if (!arrayToken) return;
const tokenPayload = JSON.parse(atob(arrayToken[1]));
// eslint-disable-next-line consistent-return
return tokenPayload.sub;
}

const sID = getSessionID();

const params = new Proxy(
// eslint-disable-next-line compat/compat
new URLSearchParams(window.location.search),
Expand All @@ -24,79 +44,85 @@ if (params.dropzone2) {
}

export default function init(eventName, verb, metaData) {
console.log(`📡 Event Name - acrobat:verb-${verb}:${eventName} - metaData: ${metaData?.type} / ${metaData?.size} `);
const event = {
documentUnloading: true,
data: {
eventType: 'web.webinteraction.linkClicks',
web: {
webInteraction: {
linkClicks: { value: 1 },
type: 'other',
name: `acrobat:verb-${verb}:${eventName}`,
},
},
_adobe_corpnew: {
digitalData: {
dcweb: {
event: { pagename: `acrobat:verb-${verb}:${eventName}` },
content: {
type: metaData?.type,
size: metaData?.size,
count: metaData?.count,
},
source: {
user_agent: navigator.userAgent,
lang: document.documentElement.lang,
app_name: 'unity:adobe_com',
url: window.location.href,
app_referrer: appReferrer,
tracking_id: trackingId,
},
user: {
locale: document.documentElement.lang.toLocaleLowerCase(),
id: 'DO WE NEED THIS?',
is_authenticated: false,
user_tags: [
`${localStorage['unity.user'] ? 'frictionless_return_user' : 'frictionless_new_user'}`,
],
},
let event;
window.addEventListener('IMS:Ready:Unity', () => {
console.log(`📡 Event Name - acrobat:verb-${verb}:${eventName} - metaData: ${metaData?.type} / ${metaData?.size} `);
event = {
documentUnloading: true,
data: {
eventType: 'web.webinteraction.linkClicks',
web: {
webInteraction: {
linkClicks: { value: 1 },
type: 'other',
name: `acrobat:verb-${verb}:${eventName}`,
},
dcweb2: {
event: { pagename: `acrobat:verb-${verb}:${eventName}` },
content: {
type: metaData?.type,
size: metaData?.size,
count: metaData?.count,
// extension: 'docx', may not be needed
},
source: {
user_agent: navigator.userAgent,
lang: document.documentElement.lang,
app_name: 'unity:adobe_com',
url: window.location.href,
app_referrer: appReferrer,
tracking_id: trackingId,
},
_adobe_corpnew: {
digitalData: {
dcweb: {
event: { pagename: `acrobat:verb-${verb}:${eventName}` },
content: {
type: metaData?.type,
size: metaData?.size,
count: metaData?.count,
},
source: {
user_agent: navigator.userAgent,
lang: document.documentElement.lang,
app_name: 'unity:adobe_com',
url: window.location.href,
app_referrer: appReferrer,
tracking_id: trackingId,
},
user: {
locale: document.documentElement.lang.toLocaleLowerCase(),
id: sID,
is_authenticated: `${window.adobeIMS?.isSignedInUser() ? 'true' : 'false'}`,
user_tags: [
`${localStorage['unity.user'] ? 'frictionless_return_user' : 'frictionless_new_user'}`,
],
},
},
user: {
locale: document.documentElement.lang.toLocaleLowerCase(),
id: 'DO WE NEED THIS?',
is_authenticated: false,
user_tags: [
`${localStorage['unity.user'] ? 'frictionless_return_user' : 'frictionless_new_user'}`,
],
dcweb2: {
event: { pagename: `acrobat:verb-${verb}:${eventName}` },
content: {
type: metaData?.type,
size: metaData?.size,
count: metaData?.count,
// extension: 'docx', may not be needed
},
source: {
user_agent: navigator.userAgent,
lang: document.documentElement.lang,
app_name: 'unity:adobe_com',
url: window.location.href,
app_referrer: appReferrer,
tracking_id: trackingId,
},
user: {
locale: document.documentElement.lang.toLocaleLowerCase(),
id: sID,
is_authenticated: `${window.adobeIMS?.isSignedInUser() ? 'true' : 'false'}`,
user_tags: [
`${localStorage['unity.user'] ? 'frictionless_return_user' : 'frictionless_new_user'}`,
],
},
},
},
},
},
},
};
};
});

// Alloy Ready...
const AlloyReady = setInterval(() => {
// eslint-disable-next-line no-underscore-dangle
if (window?._satellite?.track) {
clearInterval(AlloyReady);
// eslint-disable-next-line no-underscore-dangle
console.log(event);

window._satellite?.track('event', event);
}
}, 1000);
Expand Down

0 comments on commit 2422b33

Please sign in to comment.