diff --git a/jest.setup.ts b/jest.setup.ts index 4cb7594..62d6bbf 100644 --- a/jest.setup.ts +++ b/jest.setup.ts @@ -1,4 +1 @@ -// import { TextEncoder, TextDecoder } from 'util'; - -// global.TextEncoder = TextEncoder; -// global.TextDecoder = TextDecoder as any; +// any jest related setup here diff --git a/src/utils/analytics.ts b/src/utils/analytics.ts index 5333e95..70e1097 100644 --- a/src/utils/analytics.ts +++ b/src/utils/analytics.ts @@ -7,8 +7,8 @@ interface TrackerOptions { } interface TrackingOptions { - props?: any; - data?: any; + props?: { [key: string]: number | string } | string | number; + data?: { [key: string]: number | string } | string | number; } interface RequestBody { @@ -16,8 +16,8 @@ interface RequestBody { name: string; url: string; referrer?: string; - props?: any; - data?: any; + props?: { [key: string]: number | string } | string | number; + data?: { [key: string]: number | string } | string | number; } export class Tracker { diff --git a/src/worker.ts b/src/worker.ts index 8cc5a31..afab8e2 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -9,9 +9,10 @@ import { Tracker } from './utils/analytics'; interface ENV { DOH_GATEWAY_URL: string; + PLAUSIBLE_BASE_URL: string; } -const tracker = new Tracker('ccip-read-dns-worker.ens-cf.workers.dev', { +const tracker = new Tracker('ccip-read-dns-worker.ensdomains.workers.dev', { enableLogging: true, }); @@ -32,7 +33,7 @@ const logResult = async (request: CFWRequest, result: Response) => { return result; } const [streamForLog, streamForResult] = result.body.tee(); - const logResult = await new Response(streamForLog).json(); + const logResult: { data: string } = await new Response(streamForLog).json(); await tracker.trackEvent( request, @@ -49,6 +50,9 @@ module.exports = { env: ENV, _context: ExecutionContext ) { + if (env.PLAUSIBLE_BASE_URL) { + tracker.apiEndpoint = env.PLAUSIBLE_BASE_URL; + } await tracker.trackEvent(request, 'request', {}, true); await tracker.trackPageview(request, {}, true); const router = routeHandler(env, tracker.trackEvent.bind(tracker, request));