Skip to content

Commit

Permalink
add analytics base url env
Browse files Browse the repository at this point in the history
  • Loading branch information
mdtanrikulu committed Jan 21, 2024
1 parent 090d659 commit c67b918
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
5 changes: 1 addition & 4 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
// import { TextEncoder, TextDecoder } from 'util';

// global.TextEncoder = TextEncoder;
// global.TextDecoder = TextDecoder as any;
// any jest related setup here
8 changes: 4 additions & 4 deletions src/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ interface TrackerOptions {
}

interface TrackingOptions {
props?: any;
data?: any;
props?: { [key: string]: number | string } | string | number;
data?: { [key: string]: number | string } | string | number;
}

interface RequestBody {
domain: string;
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 {
Expand Down
8 changes: 6 additions & 2 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand All @@ -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,
Expand All @@ -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));
Expand Down

0 comments on commit c67b918

Please sign in to comment.