Skip to main content
Module

x/blog/deps.ts>createReporter

Minimal boilerplate blogging.
Go to Latest
function createReporter
import { createReporter } from "https://deno.land/x/blog@0.5.0/deps.ts";

Create and return a function which will dispatch messages to Google Analytics.

Examples

Using std/http

import { createReporter } from "https://deno.land/x/g_a/mod.ts";
import { serve } from "https://deno.land/std/http/server.ts";
import type { ConnInfo } from "https://deno.land/std/http/server.ts";

const ga = createReporter();

function handler(req: Request, conn: ConnInfo) {
  let err;
  let res: Response;
  const start = performance.now();
  try {
    // processing of the request...
    res = new Response();
  } catch (e) {
    err = e;
  } finally {
    ga(req, conn, res!, start, err);
  }
  return res!;
}

serve(handler);

Using low level APIs

import { createReporter } from "https://deno.land/x/g_a/mod.ts";

const ga = createReporter();

for await (const conn of Deno.listen({ port: 0 })) {
  (async () => {
    const httpConn = Deno.serveHttp(conn);
    for await (const requestEvent of httpConn) {
      let err;
      const start = performance.now();
      try {
        // processing of the request...
        const response = new Response();
        await requestEvent.respondWith(response);
      } catch (e) {
        err = e;
      } finally {
        await ga(requestEvent.request, conn, response, start, err);
      }
    }
  })();
}

Parameters

optional
options: ReporterOptions = [UNSUPPORTED]

an optional set of options the impact the behavior of the returned reporter.

Returns

Reporter

the reporter function used to enqueue messages to dispatch to Google Analytics.