Skip to content

Commit

Permalink
Merge pull request #773 from adobecom/mwpw-154526-acom-widget-analytics
Browse files Browse the repository at this point in the history
Analytics for acom widget
  • Loading branch information
Blainegunn committed Sep 3, 2024
2 parents a3647cd + ad2c2d2 commit 0c298f1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
16 changes: 16 additions & 0 deletions acrobat/blocks/acom-widget/acom-widget.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import LIMITS from './limits.js';
import { setLibs } from '../../scripts/utils.js';
import acomAnalytics from '../../scripts/alloy/acom-widget.js';

const miloLibs = setLibs('/libs');
const { createTag } = await import(`${miloLibs}/utils/utils.js`);
Expand All @@ -23,17 +24,20 @@ const sendToUnity = async (file, verb, err, errTxt) => {

// Error Check: File Empty
if (file.size < 1) {
acomAnalytics('error:step01:empty-file', verb);
handleError(err, errTxt, 'acom-widget-error-empty');
}

// Error Check: Supported File Type
if (LIMITS[verb].acceptedFiles.indexOf(file.type) < 0) {
acomAnalytics('error:step01:unsupported-file-type', verb);
handleError(err, errTxt, 'acom-widget-error-unsupported');
return;
}

// Error Check: File Too Large
if (file.size > LIMITS[verb].maxFileSize) {
acomAnalytics('error:step01:file-too-large', verb);
handleError(err, errTxt, 'acom-widget-error-large', LIMITS[verb].maxFileSizeFriendly);
}

Expand Down Expand Up @@ -177,7 +181,14 @@ export default async function init(element) {

element.append(widget, footer);

acomAnalytics('landing:shown', VERB);

button.addEventListener('click', () => {
acomAnalytics('dropzone:choose-file-clicked', VERB);
});

button.addEventListener('change', (e) => {
acomAnalytics('choose-file:open', VERB);
const file = e.target.files[0];
if (file) {
sendToUnity(file, VERB, errorState, errorStateText);
Expand All @@ -186,6 +197,10 @@ export default async function init(element) {
e.target.value = '';
});

button.addEventListener('cancel', () => {
acomAnalytics('choose-file:close', VERB);
});

widget.addEventListener('dragover', (e) => {
e.preventDefault();
setDraggingClass(widget, true);
Expand All @@ -196,6 +211,7 @@ export default async function init(element) {
});

widget.addEventListener('drop', (e) => {
acomAnalytics('files-dropped', VERB);
dropFiles(e, VERB, errorState, errorStateText);
setDraggingClass(widget, false);
});
Expand Down
31 changes: 31 additions & 0 deletions acrobat/scripts/alloy/acom-widget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export default function init(eventName, verb) {
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}` } },
dcweb2: { event: { pagename: `acrobat:verb-${verb}:${eventName}` } },
},
},
},
};
// 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
window._satellite?.track('event', event);
}
}, 1000);
// eslint-disable-next-line no-underscore-dangle
}

0 comments on commit 0c298f1

Please sign in to comment.