Skip to content

Commit

Permalink
Pass custom apiEndpoint and props
Browse files Browse the repository at this point in the history
  • Loading branch information
makoto committed Jan 25, 2024
1 parent c6ac180 commit ef835e8
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions arb-gateway/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,22 @@ interface Env {

let app: Router;
const tracker = new Tracker('arb-sepolia-gateway-worker.ens-cf.workers.dev', {
apiEndpoint:'https://plausible.pff.sh/api/event',
enableLogging: true,
});

const decodeUrl = (url:string) => {
const trackingData = (url).match(/\/0x[a-fA-F0-9]{40}\/0x[a-fA-F0-9]{1,}\.json/)
if(trackingData){
return{
sender: trackingData[0].slice(1,42),
calldata:trackingData[0].slice(44).replace(".json","")
}
}else{
return {}
}
}

const logResult = async (
request: CFWRequest,
result: Response
Expand All @@ -26,10 +40,11 @@ const logResult = async (
const [streamForLog, streamForResult] = result.body.tee();
const logResult:any = await new Response(streamForLog).json();
const logResultData = logResult.data.substring(0, 200);
const props = decodeUrl(request.url)
await tracker.trackEvent(
request,
'result',
{ props: { result: logResultData } },
{ props: {...props, result: logResultData } },
true
);
return new Response(streamForResult, result);
Expand Down Expand Up @@ -63,8 +78,12 @@ async function fetch(request: CFWRequest, env: Env) {
gateway.add(server);
app = server.makeApp('/');
}
const props = decodeUrl(request.url)
await tracker.trackEvent(
request, 'request',{},true
request,
'request',
{ props: {...props, ...{} } },
true
);

return app.handle(request).then(logResult.bind(null, request));
Expand Down

0 comments on commit ef835e8

Please sign in to comment.