Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MWPW-158477]-Send analytics for acrobat fiil and sign #116

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions unitylibs/core/workflow/workflow-acrobat/action-binder.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default class ActionBinder {
return createTag('div', { class: 'progress-holder' }, pdom);
}

async acrobatActionMaps(values, files) {
async acrobatActionMaps(values, files, eventName) {
await this.handlePreloads();
const { default: ServiceHandler } = await import(`${getUnityLibs()}/core/workflow/${this.workflowCfg.name}/service-handler.js`);
this.serviceHandler = new ServiceHandler(
Expand All @@ -80,7 +80,7 @@ export default class ActionBinder {
switch (true) {
case value.actionType === 'fillsign':
this.promiseStack = [];
await this.fillsign(files);
await this.fillsign(files, eventName);
break;
case value.actionType === 'continueInApp':
await this.continueInApp();
Expand Down Expand Up @@ -108,16 +108,14 @@ export default class ActionBinder {
case el.nodeName === 'DIV':
el.addEventListener('drop', async (e) => {
e.preventDefault();
this.block.dispatchEvent(new CustomEvent(unityConfig.trackAnalyticsEvent, { detail: { event: 'drop' } }));
const files = this.extractFiles(e);
await this.acrobatActionMaps(values, files);
await this.acrobatActionMaps(values, files, 'drop');
});
break;
case el.nodeName === 'INPUT':
el.addEventListener('change', async (e) => {
this.block.dispatchEvent(new CustomEvent(unityConfig.trackAnalyticsEvent, { detail: { event: 'change' } }));
const files = this.extractFiles(e);
await this.acrobatActionMaps(values, files);
await this.acrobatActionMaps(values, files, 'change');
e.target.value = '';
});
break;
Expand Down Expand Up @@ -156,14 +154,14 @@ export default class ActionBinder {
));
}

async fillsign(files) {
async fillsign(files, eventName) {
if (!files || files.length > this.limits.maxNumFiles) {
this.dispatchErrorToast('verb_upload_error_only_accept_one_file');
return;
}
const file = files[0];
if (!file) return;
this.singleFileUpload(file);
this.singleFileUpload(file, eventName);
}

async getBlobData(file) {
Expand Down Expand Up @@ -320,7 +318,7 @@ export default class ActionBinder {
}
}

async singleFileUpload(file) {
async singleFileUpload(file, eventName) {
if (file.type !== 'application/pdf') {
this.dispatchErrorToast('verb_upload_error_unsupported_type');
return;
Expand All @@ -333,6 +331,16 @@ export default class ActionBinder {
this.dispatchErrorToast('verb_upload_error_file_too_large');
return;
}
const fileData = {
type: file.type,
size: file.size,
count: 1,
};
this.block.dispatchEvent(
new CustomEvent(unityConfig.trackAnalyticsEvent, {
detail: { event: eventName, data: fileData },
}),
);
let assetData = null;
try {
await this.showSplashScreen(true);
Expand All @@ -348,6 +356,7 @@ export default class ActionBinder {
this.acrobatApiConfig.acrobatEndpoint.createAsset,
{ body: JSON.stringify(data) },
);
this.block.dispatchEvent(new CustomEvent(unityConfig.trackAnalyticsEvent, { detail: { event: 'uploading' } }));
await this.chunkPdf(assetData, blobData, file.type);
const operationItem = {
assetId: assetData.id,
Expand All @@ -363,5 +372,7 @@ export default class ActionBinder {
return;
}
this.verifyContent(assetData);
// TODO: Call to check for asset metadata of uploaded file goes here
this.block.dispatchEvent(new CustomEvent(unityConfig.trackAnalyticsEvent, { detail: { event: 'uploaded' } }));
}
}