Skip to content

Commit

Permalink
test-uploaded updated
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinrivero committed Dec 19, 2024
1 parent ce6fa7e commit 0412b8e
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 4 deletions.
10 changes: 7 additions & 3 deletions acrobat/blocks/verb-widget/verb-widget.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import LIMITS from './limits.js';
import { setLibs, getEnv, isOldBrowser } from '../../scripts/utils.js';
import verbAnalytics from '../../scripts/alloy/verb-widget.js';
import { verbAnalytics, verbAnalyticsRedirect } from '../../scripts/alloy/verb-widget.js';
import createSvgElement from './icons.js';

const miloLibs = setLibs('/libs');
Expand Down Expand Up @@ -273,12 +273,16 @@ export default async function init(element) {
document.cookie = `UTS_Uploaded=${Date.now()};domain=.adobe.com;path=/;expires=${cookieExp}`;
}
});

window.addEventListener('beforeunload', () => {
const beforeunloadHandler = () => {
verbAnalyticsRedirect('job:test-uploaded', VERB);
const cookieExp = new Date(Date.now() + 90 * 1000).toUTCString();
if (exitFlag) {
document.cookie = `UTS_Redirect=${Date.now()};domain=.adobe.com;path=/;expires=${cookieExp}`;
}
};

window.addEventListener('beforeunload', () => {
beforeunloadHandler();
});

// Errors, Analytics & Logging
Expand Down
110 changes: 109 additions & 1 deletion acrobat/scripts/alloy/verb-widget.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
const params = new Proxy(
// eslint-disable-next-line compat/compat
new URLSearchParams(window.location.search),
Expand All @@ -23,7 +24,7 @@ if (params.dropzone2) {
appTags.push('dropzone2');
}

export default function init(eventName, verb, metaData) {
export function verbAnalytics(eventName, verb, metaData) {
function getSessionID() {
const aToken = window.adobeIMS.getAccessToken();
const arrayToken = aToken?.token.split('.');
Expand Down Expand Up @@ -114,5 +115,112 @@ export default function init(eventName, verb, metaData) {
window._satellite?.track('event', event);
}
}, 1000);
}

function handlePropositions(AJOPropositionResult) {
console.log('AJOPropositionResult:', AJOPropositionResult);
// eslint-disable-next-line no-underscore-dangle
window._satellite.track('propositionDisplay', AJOPropositionResult.propositions);
}

export async function verbAnalyticsRedirect(eventName, verb, metaData, documentUnloading = false) {
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 || tokenPayload.user_id;
}
const event = {
documentUnloading,
data: {
eventType: 'web.webinteraction.linkClicks',
web: {
webInteraction: {
linkClicks: { value: 1 },
type: 'other',
name: `acrobat:verb-${verb}:${eventName}`,
},
},
_adobe_corpnew: {
digitalData: {
primaryEvent: {
eventInfo: {
eventName: `acrobat:verb-${verb}:${eventName}`,
value: `${verb} - Frictionless to Acrobat Web`,
},
},
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: getSessionID(),
is_authenticated: `${window.adobeIMS?.isSignedInUser() ? 'true' : '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: getSessionID(),
is_authenticated: `${window.adobeIMS?.isSignedInUser() ? 'true' : 'false'}`,
user_tags: [
`${localStorage['unity.user'] ? 'frictionless_return_user' : 'frictionless_new_user'}`,
],
},
},
},
},
},
// eslint-disable-next-line
done: function (AJOPropositionResult, error) {
if (error) {
console.error('[AJO Fetch Error]:', error);
return;
}
handlePropositions(AJOPropositionResult);
// eslint-disable-next-line no-underscore-dangle
window._satellite.track('propositionDisplay', AJOPropositionResult.propositions);
},
};

const AlloyReady = setInterval(() => {
// eslint-disable-next-line no-underscore-dangle
if (window?._satellite?.track) {
clearInterval(AlloyReady);
// eslint-disable-next-line no-underscore-dangle
window._satellite?.track('event', event);
}
}, 3000);
}

0 comments on commit 0412b8e

Please sign in to comment.