diff --git a/acrobat/blocks/verb-widget/verb-widget.js b/acrobat/blocks/verb-widget/verb-widget.js index 7e2956b1..a01ae945 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,44 +7,23 @@ const { createTag } = await import(`${miloLibs}/utils/utils.js`); const EOLBrowserPage = 'https://acrobat.adobe.com/home/index-browser-eol.html'; -// 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:step01: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); -// 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); -// } -// }; +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); +}; const setDraggingClass = (widget, shouldToggle) => { + // eslint-disable-next-line chai-friendly/no-unused-expressions shouldToggle ? widget.classList.add('dragging') : widget.classList.remove('dragging'); }; @@ -112,10 +90,15 @@ export default async function init(element) { element.append(widget, footer); + // Analytics verbAnalytics('landing:shown', VERB); + widgetMobileButton.addEventListener('click', () => { + verbAnalytics('goto-app:clicked', VERB); + }); + button.addEventListener('click', () => { - verbAnalytics('dropzone:choose-file-clicked', VERB); + verbAnalytics('filepicker:shown', VERB); }); button.addEventListener('cancel', () => { @@ -137,12 +120,68 @@ 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') { - verbAnalytics('files-dropped', VERB); + // maybe new event name files-dropped? + if (e.detail?.event === 'drop') { + 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) => { + 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); + } + + 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) diff --git a/acrobat/scripts/alloy/verb-widget.js b/acrobat/scripts/alloy/verb-widget.js index b36f889b..c5829ac9 100644 --- a/acrobat/scripts/alloy/verb-widget.js +++ b/acrobat/scripts/alloy/verb-widget.js @@ -1,4 +1,30 @@ +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) { + console.log(`📡 Event Name - acrobat:verb-${verb}:${eventName}`); const event = { documentUnloading: true, data: { @@ -12,8 +38,56 @@ 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}` }, + content: { + type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + size: '2-5MB', + count: 1, + extension: 'docx', + }, + 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}` }, + content: { + type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + size: '2-5MB', + count: 1, + extension: 'docx', + }, + 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'}`, + ], + }, + }, }, }, },