Posthog multitool (#2301)

* Posthog functionality

* Posthog in multitool

* check if anylitics enabled
This commit is contained in:
reecebrowne 2024-11-22 17:38:44 +00:00 committed by GitHub
parent 543ad083a2
commit 547f23fe78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -122,12 +122,24 @@ class PdfContainer {
async addFilesFromFiles(files, nextSiblingElement) {
this.fileName = files[0].name;
for (var i = 0; i < files.length; i++) {
const startTime = Date.now();
let processingTime, errorMessage = null, pageCount = 0;
try {
const file = files[i];
if (file.type === "application/pdf") {
await this.addPdfFile(file, nextSiblingElement);
const { renderer, pdfDocument } = await this.loadFile(file);
pageCount = renderer.pageCount || 0;
await this.addPdfFile(renderer, pdfDocument, nextSiblingElement);
} else if (file.type.startsWith("image/")) {
await this.addImageFile(file, nextSiblingElement);
}
processingTime = Date.now() - startTime;
this.captureFileProcessingEvent(true, file, processingTime, null, pageCount);
} catch (error) {
processingTime = Date.now() - startTime;
errorMessage = error.message || "Unknown error";
this.captureFileProcessingEvent(false, files[i], processingTime, errorMessage, pageCount);
}
}
document.querySelectorAll(".enable-on-file").forEach((element) => {
@ -135,6 +147,23 @@ class PdfContainer {
});
}
captureFileProcessingEvent(success, file, processingTime, errorMessage, pageCount) {
try{
if(analyticsEnabled){
posthog.capture('file_processing', {
success,
file_type: file?.type || 'unknown',
file_size: file?.size || 0,
processing_time: processingTime,
error_message: errorMessage,
pdf_pages: pageCount,
});
}
}catch{
}
}
async addFilesBlank(nextSiblingElement) {
const pdfContent = `
%PDF-1.4
@ -188,9 +217,7 @@ class PdfContainer {
}
async addPdfFile(file, nextSiblingElement) {
const { renderer, pdfDocument } = await this.loadFile(file);
async addPdfFile(renderer, pdfDocument, nextSiblingElement) {
for (var i = 0; i < renderer.pageCount; i++) {
const div = document.createElement("div");