From 5abd28fd77bafe9685d3a2a616409560b6c394da Mon Sep 17 00:00:00 2001 From: Blaine Gunn Date: Wed, 18 Sep 2024 17:43:15 -0600 Subject: [PATCH 1/3] MWPW-158122 --- acrobat/blocks/verb-widget/verb-widget.js | 24 +++++++-- acrobat/scripts/alloy/verb-widget.js | 65 ++++++++++++++++++++++- 2 files changed, 82 insertions(+), 7 deletions(-) diff --git a/acrobat/blocks/verb-widget/verb-widget.js b/acrobat/blocks/verb-widget/verb-widget.js index cc54d9e0..73a766dd 100644 --- a/acrobat/blocks/verb-widget/verb-widget.js +++ b/acrobat/blocks/verb-widget/verb-widget.js @@ -1,4 +1,3 @@ - import LIMITS from './limits.js'; import { setLibs, isOldBrowser } from '../../scripts/utils.js'; import verbAnalytics from '../../scripts/alloy/verb-widget.js'; @@ -8,6 +7,10 @@ const { createTag } = await import(`${miloLibs}/utils/utils.js`); const EOLBrowserPage = 'https://acrobat.adobe.com/home/index-browser-eol.html'; +const setUser = () => { + localStorage.setItem('unity.user', 'true'); +}; + // const handleError = (err, errTxt, str, strTwo) => { // err.classList.add('verb-error'); // err.classList.remove('hide'); @@ -27,13 +30,13 @@ const EOLBrowserPage = 'https://acrobat.adobe.com/home/index-browser-eol.html'; // const sendToUnity = async (file, verb, err, errTxt) => { // // Error Check: File Empty // if (file.size < 1) { -// verbAnalytics('error:step01:empty-file', verb); +// verbAnalytics('error:empty_file', verb); // handleError(err, errTxt, 'verb-widget-error-empty'); // } // // Error Check: Supported File Type // if (LIMITS[verb].acceptedFiles.indexOf(file.type) < 0) { -// verbAnalytics('error:step01:unsupported-file-type', verb); +// verbAnalytics('error:unsupported_type', verb); // handleError(err, errTxt, 'verb-widget-error-unsupported'); // return; // } @@ -44,6 +47,8 @@ const EOLBrowserPage = 'https://acrobat.adobe.com/home/index-browser-eol.html'; // handleError(err, errTxt, 'verb-widget-error-large', LIMITS[verb].maxFileSizeFriendly); // } // }; +// Page: Upload Error acrobat:verb-fillsign:error +// Page: Upload Error acrobat:verb-fillsign:error:max_page_count const setDraggingClass = (widget, shouldToggle) => { shouldToggle ? widget.classList.add('dragging') : widget.classList.remove('dragging'); @@ -108,6 +113,10 @@ export default async function init(element) { verbAnalytics('landing:shown', VERB); + widgetMobileButton.addEventListener('click', () => { + verbAnalytics('goto-app:clicked', VERB); + }); + button.addEventListener('click', () => { verbAnalytics('dropzone:choose-file-clicked', VERB); }); @@ -116,6 +125,9 @@ export default async function init(element) { verbAnalytics('choose-file:close', VERB); }); + // Page : File upload events acrobat:verb-fillsign:job:uploaded + // Page : File upload events acrobat:verb-fillsign:job:uploading + widget.addEventListener('dragover', (e) => { e.preventDefault(); setDraggingClass(widget, true); @@ -131,12 +143,14 @@ export default async function init(element) { }); window.addEventListener('unity:track-analytics', (e) => { - if (e.detail.event === 'change') { + if (e.detail?.event === 'change') { verbAnalytics('choose-file:open', VERB); + setUser(); } - if (e.detail.event === 'drop') { + if (e.detail?.event === 'drop') { verbAnalytics('files-dropped', VERB); setDraggingClass(widget, false); + setUser(); } }); } diff --git a/acrobat/scripts/alloy/verb-widget.js b/acrobat/scripts/alloy/verb-widget.js index b36f889b..73624ed8 100644 --- a/acrobat/scripts/alloy/verb-widget.js +++ b/acrobat/scripts/alloy/verb-widget.js @@ -1,3 +1,28 @@ +const params = new Proxy( + // eslint-disable-next-line compat/compat + new URLSearchParams(window.location.search), + { get: (searchParams, prop) => searchParams.get(prop) }, +); + +let appReferrer = params.x_api_client_id || params['x-product'] || ''; +if (params.x_api_client_location || params['x-product-location']) { + appReferrer = `${appReferrer}:${params.x_api_client_location || params['x-product-location']}`; +} +let trackingId = params.trackingid || ''; +if (params.mv) { + trackingId = `${trackingId}:${params.mv}`; +} +if (params.mv2) { + trackingId = `${trackingId}:${params.mv2}`; +} +const appTags = []; +if (params.workflow) { + appTags.push(params.workflow); +} +if (params.dropzone2) { + appTags.push('dropzone2'); +} + export default function init(eventName, verb) { const event = { documentUnloading: true, @@ -12,8 +37,44 @@ export default function init(eventName, verb) { }, _adobe_corpnew: { digitalData: { - dcweb: { event: { pagename: `acrobat:verb-${verb}:${eventName}` } }, - dcweb2: { event: { pagename: `acrobat:verb-${verb}:${eventName}` } }, + dcweb: { + event: { pagename: `acrobat:verb-${verb}:${eventName}` }, + 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'}`, + ], + }, + }, + dcweb2: { + event: { pagename: `acrobat:verb-${verb}:${eventName}` }, + 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'}`, + ], + }, + }, }, }, }, From aa541ddcc01f496fc8759c56c1ced490d39f4b1d Mon Sep 17 00:00:00 2001 From: Blaine Gunn Date: Thu, 19 Sep 2024 13:30:11 -0600 Subject: [PATCH 2/3] updates --- acrobat/blocks/verb-widget/verb-widget.js | 108 +++++++++++++--------- 1 file changed, 65 insertions(+), 43 deletions(-) diff --git a/acrobat/blocks/verb-widget/verb-widget.js b/acrobat/blocks/verb-widget/verb-widget.js index 73a766dd..bfa3b650 100644 --- a/acrobat/blocks/verb-widget/verb-widget.js +++ b/acrobat/blocks/verb-widget/verb-widget.js @@ -11,44 +11,16 @@ const setUser = () => { localStorage.setItem('unity.user', 'true'); }; -// const handleError = (err, errTxt, str, strTwo) => { -// err.classList.add('verb-error'); -// err.classList.remove('hide'); -// errTxt.textContent = `${window.mph[str]} ${strTwo || ''}`; - -// setTimeout(() => { -// err.classList.remove('verb-error'); -// err.classList.add('hide'); -// }, 5000); - -// // Add LANA Logs and AA -// }; - -// This function is no longer needed, I'll remove after we get error event from Unity team. -// handleError() is will need to be uncommented out too. - -// const sendToUnity = async (file, verb, err, errTxt) => { -// // Error Check: File Empty -// if (file.size < 1) { -// verbAnalytics('error:empty_file', verb); -// handleError(err, errTxt, 'verb-widget-error-empty'); -// } - -// // Error Check: Supported File Type -// if (LIMITS[verb].acceptedFiles.indexOf(file.type) < 0) { -// verbAnalytics('error:unsupported_type', verb); -// handleError(err, errTxt, 'verb-widget-error-unsupported'); -// return; -// } - -// // Error Check: File Too Large -// if (file.size > LIMITS[verb].maxFileSize) { -// verbAnalytics('error:step01:file-too-large', verb); -// handleError(err, errTxt, 'verb-widget-error-large', LIMITS[verb].maxFileSizeFriendly); -// } -// }; -// Page: Upload Error acrobat:verb-fillsign:error -// Page: Upload Error acrobat:verb-fillsign:error:max_page_count +const handleError = (err, errTxt, str, strTwo) => { + err.classList.add('verb-error'); + err.classList.remove('hide'); + errTxt.textContent = `${window.mph[str]} ${strTwo || ''}`; + + setTimeout(() => { + err.classList.remove('verb-error'); + err.classList.add('hide'); + }, 5000); +}; const setDraggingClass = (widget, shouldToggle) => { shouldToggle ? widget.classList.add('dragging') : widget.classList.remove('dragging'); @@ -111,6 +83,7 @@ export default async function init(element) { element.append(widget, footer); + // Analytics verbAnalytics('landing:shown', VERB); widgetMobileButton.addEventListener('click', () => { @@ -118,16 +91,13 @@ export default async function init(element) { }); button.addEventListener('click', () => { - verbAnalytics('dropzone:choose-file-clicked', VERB); + verbAnalytics('filepicker:shown', VERB); }); button.addEventListener('cancel', () => { verbAnalytics('choose-file:close', VERB); }); - // Page : File upload events acrobat:verb-fillsign:job:uploaded - // Page : File upload events acrobat:verb-fillsign:job:uploading - widget.addEventListener('dragover', (e) => { e.preventDefault(); setDraggingClass(widget, true); @@ -147,10 +117,62 @@ export default async function init(element) { verbAnalytics('choose-file:open', VERB); setUser(); } + // maybe new event name files-dropped? if (e.detail?.event === 'drop') { - verbAnalytics('files-dropped', VERB); + verbAnalytics('files-dropped', VERB, e.detail?.data); setDraggingClass(widget, false); setUser(); } + if (e.detail?.event === 'choose-file-clicked') { + verbAnalytics('dropzone:choose-file-clicked', VERB, e.detail?.data); + setUser(); + } + + if (e.detail?.event === 'uploading') { + verbAnalytics('job:uploading', VERB, e.detail?.data); + setUser(); + } + + if (e.detail?.event === 'uploaded') { + verbAnalytics('job:uploaded', VERB, e.detail?.data); + setUser(); + } + }); + + // Errors, Analytics & Logging + window.addEventListener('unity:show-error-toast', (e) => { + if (e.detail?.code === 'only_accept_one_file') { + handleError(errorState, errorStateText, 'verb-widget-error-multi'); + verbAnalytics('error', VERB); + } + + if (e.detail?.code === 'unsupported_type') { + handleError(errorState, errorStateText, 'verb-widget-error-unsupported'); + verbAnalytics('error:unsupported_type', VERB); + } + + if (e.detail?.code === 'empty_file') { + handleError(errorState, errorStateText, 'verb-widget-error-empty'); + verbAnalytics('error:empty_file', VERB); + } + + // Code may be wrong. should be 'file_too_large' + if (e.detail?.code === 'file_too_largempty_file') { + handleError(errorState, errorStateText, 'verb-widget-error-large', LIMITS[VERB].maxFileSizeFriendly); + verbAnalytics('error', VERB); + } + + if (e.detail?.code === 'max_page_count') { + handleError(errorState, errorStateText, 'verb-widget-error-max', LIMITS[VERB].maxNumFiles); + verbAnalytics('error:max_page_count', VERB); + } + + // acrobat:verb-fillsign:error:page_count_missing_from_metadata_api + // acrobat:verb-fillsign:error:403 + // acrobat:verb-fillsign:error + // LANA for 403 }); } + +// const ce = (new CustomEvent('unity:show-error-toast', { detail: { code: 'only_accept_one_file', message: 'Error message' } })); +// dispatchEvent(ce) From 86776f3c1eb4daecbd88b23ee20ab5189acfde3e Mon Sep 17 00:00:00 2001 From: Blaine Gunn Date: Thu, 19 Sep 2024 14:25:34 -0600 Subject: [PATCH 3/3] console logs for ez debug --- acrobat/blocks/verb-widget/verb-widget.js | 3 +++ acrobat/scripts/alloy/verb-widget.js | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/acrobat/blocks/verb-widget/verb-widget.js b/acrobat/blocks/verb-widget/verb-widget.js index bfa3b650..4b0281b6 100644 --- a/acrobat/blocks/verb-widget/verb-widget.js +++ b/acrobat/blocks/verb-widget/verb-widget.js @@ -23,6 +23,7 @@ const handleError = (err, errTxt, str, strTwo) => { }; const setDraggingClass = (widget, shouldToggle) => { + // eslint-disable-next-line chai-friendly/no-unused-expressions shouldToggle ? widget.classList.add('dragging') : widget.classList.remove('dragging'); }; @@ -141,6 +142,8 @@ export default async function init(element) { // Errors, Analytics & Logging window.addEventListener('unity:show-error-toast', (e) => { + console.log(`⛔️ Error Code - ${e.detail?.code}`); + if (e.detail?.code === 'only_accept_one_file') { handleError(errorState, errorStateText, 'verb-widget-error-multi'); verbAnalytics('error', VERB); diff --git a/acrobat/scripts/alloy/verb-widget.js b/acrobat/scripts/alloy/verb-widget.js index 73624ed8..c5829ac9 100644 --- a/acrobat/scripts/alloy/verb-widget.js +++ b/acrobat/scripts/alloy/verb-widget.js @@ -24,6 +24,7 @@ if (params.dropzone2) { } export default function init(eventName, verb) { + console.log(`📡 Event Name - acrobat:verb-${verb}:${eventName}`); const event = { documentUnloading: true, data: { @@ -39,6 +40,12 @@ export default function init(eventName, verb) { digitalData: { dcweb: { event: { pagename: `acrobat:verb-${verb}:${eventName}` }, + content: { + type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + size: '2-5MB', + count: 1, + extension: 'docx', + }, source: { user_agent: navigator.userAgent, lang: document.documentElement.lang, @@ -58,6 +65,12 @@ export default function init(eventName, verb) { }, dcweb2: { event: { pagename: `acrobat:verb-${verb}:${eventName}` }, + content: { + type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + size: '2-5MB', + count: 1, + extension: 'docx', + }, source: { user_agent: navigator.userAgent, lang: document.documentElement.lang,