refactor: use capture

This commit is contained in:
karishmas6
2024-10-29 03:46:13 +05:30
parent 9a851a8650
commit 12eee989a1
3 changed files with 27 additions and 20 deletions

View File

@@ -21,7 +21,7 @@ import fs from "fs";
import { getBestSelectorForAction } from "../utils";
import { browserPool } from "../../server";
import { uuid } from "uuidv4";
import captureServerAnalytics from "../../utils/analytics"
import { capture } from "../../utils/analytics"
interface PersistedGeneratedData {
lastUsedSelector: string;
@@ -496,14 +496,13 @@ export class WorkflowGenerator {
recording_meta: this.recordingMeta,
recording: recording,
});
captureServerAnalytics.capture({
distinctId: userId.toString(),
event: 'maxun-oss-robot-created',
properties: {
capture(
'maxun-oss-robot-created',
{
robot_meta: robot.recording_meta,
recording: robot.recording,
}
})
)
logger.log('info', `Robot saved with id: ${robot.id}`);
}

View File

@@ -24,8 +24,18 @@ export async function updateGoogleSheet(robotId: string, runId: string) {
const plainRun = run.toJSON();
if (plainRun.status === 'success' && plainRun.serializableOutput) {
const data = plainRun.serializableOutput['item-0'] as { [key: string]: any }[];
if (plainRun.status === 'success') {
let data: { [key: string]: any }[] = [];
if (plainRun.serializableOutput && Object.keys(plainRun.serializableOutput).length > 0) {
data = plainRun.serializableOutput['item-0'] as { [key: string]: any }[];
} else if (plainRun.binaryOutput && plainRun.binaryOutput['item-0']) {
// Handle binaryOutput by setting the URL as a data entry
const binaryUrl = plainRun.binaryOutput['item-0'] as string;
// Create a placeholder object with the binary URL
data = [{ "Screenshot URL": binaryUrl }];
}
const robot = await Robot.findOne({ where: { 'recording_meta.id': robotId } });

View File

@@ -9,7 +9,7 @@ import Robot from "../../models/Robot";
import Run from "../../models/Run";
import { getDecryptedProxyConfig } from "../../routes/proxy";
import { BinaryOutputService } from "../../storage/mino";
import captureServerAnalytics from "../../utils/analytics";
import { capture } from "../../utils/analytics";
async function createWorkflowAndStoreMetadata(id: string, userId: string) {
try {
@@ -50,7 +50,7 @@ async function createWorkflowAndStoreMetadata(id: string, userId: string) {
const runId = uuid();
const run = await Run.create({
status: 'Scheduled',
status: 'scheduled',
name: recording.recording_meta.name,
robotId: recording.id,
robotMetaId: recording.recording_meta.id,
@@ -139,10 +139,9 @@ async function executeRun(id: string) {
}
);
captureServerAnalytics.capture({
distinctId: id,
event: 'maxun-oss-run-created-scheduled',
properties: {
capture(
'maxun-oss-run-created-scheduled',
{
runId: id,
created_at: new Date().toISOString(),
status: 'success',
@@ -150,7 +149,7 @@ async function executeRun(id: string) {
extractedRowsCount: totalRowsExtracted,
extractedScreenshotsCount: run.dataValues.binaryOutput['item-0'].length,
}
});
);
googleSheetUpdateTasks[id] = {
robotId: plainRun.robotMetaId,
@@ -170,15 +169,14 @@ async function executeRun(id: string) {
finishedAt: new Date().toLocaleString(),
});
}
captureServerAnalytics.capture({
distinctId: id,
event: 'maxun-oss-run-created-scheduled',
properties: {
capture(
'maxun-oss-run-created-scheduled',
{
runId: id,
created_at: new Date().toISOString(),
status: 'failed',
}
});
);
return false;
}
}