{"id":15045913,"url":"https://github.com/denoland/ga","last_synced_at":"2025-10-11T04:48:20.834Z","repository":{"id":40706748,"uuid":"446280108","full_name":"denoland/ga","owner":"denoland","description":"Utilities for server side processing of Google Analytics in Deno CLI and Deploy","archived":false,"fork":false,"pushed_at":"2023-05-30T23:02:31.000Z","size":21,"stargazers_count":38,"open_issues_count":4,"forks_count":8,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-09-25T23:41:15.450Z","etag":null,"topics":["deno","deploy","ga","google-analytics"],"latest_commit_sha":null,"homepage":"https://deno.land/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/denoland.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-10T04:29:01.000Z","updated_at":"2024-05-17T04:51:15.000Z","dependencies_parsed_at":"2024-09-25T01:59:10.856Z","dependency_job_id":"ab418cbb-a4d1-468c-ba3e-ffb1488735c6","html_url":"https://github.com/denoland/ga","commit_stats":{"total_commits":8,"total_committers":3,"mean_commits":"2.6666666666666665","dds":0.25,"last_synced_commit":"f7c6b1c9407da69d003ad749b9e63953a2ac3e55"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/denoland/ga","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denoland%2Fga","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denoland%2Fga/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denoland%2Fga/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denoland%2Fga/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denoland","download_url":"https://codeload.github.com/denoland/ga/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denoland%2Fga/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006216,"owners_count":26084062,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","deploy","ga","google-analytics"],"created_at":"2024-09-24T20:52:27.107Z","updated_at":"2025-10-11T04:48:20.807Z","avatar_url":"https://github.com/denoland.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ga\n\n[![oak ci](https://github.com/denoland/ga/workflows/ci/badge.svg)](https://github.com/denoland/ga)\n[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/g_a/mod.ts)\n\nUtilities for server side processing of Google Analytics in Deno CLI and Deploy.\n\nWhen you server side render pages, it can be more efficient to not add Google\nAnalytics to the client side app, and instead send the messages directly via\nyour edge worker. This library provides a framework for doing this.\n\n## Usage\n\nThe library is designed to generate a measure message for each request and\nresponse handled by a Deno CLI or Deno Deploy server. These messages are then\nqueued up and asynchronously batched to Google Analytics.\n\n### `createReporter()`\n\nIf you are using the Deno HTTP APIs directly, `std/http`, or various other HTTP\nframeworks, `createReporter()` will return a function which can be used to\ndispatch messages to Google Analytics.\n\nYou need to create the reporter function, and then call the reporter with\ninformation about the current request and response.\n\n```ts\nimport { createReporter } from \"https://deno.land/x/g_a/mod.ts\";\n\nconst reporter = createReporter();\n```\n\nIf you are using the\n[low-level Deno API](https://deno.land/manual/runtime/http_server_apis_low_level)\nfor HTTP servers, usage of the reporter would look something like this:\n\n```ts\nimport { createReporter } from \"https://deno.land/x/g_a/mod.ts\";\n\nconst ga = createReporter();\n\nfor await (const conn of Deno.listen({ port: 0 })) {\n  (async () =\u003e {\n    const httpConn = Deno.serveHttp(conn);\n    for await (const requestEvent of httpConn) {\n      let err;\n      const start = performance.now();\n      try {\n        // processing of the request...\n        const response = new Response(/* response details */);\n        await requestEvent.respondWith(response);\n      } catch (e) {\n        err = e;\n      } finally {\n        await ga(requestEvent.request, conn, response, start, err);\n      }\n    }\n  })();\n}\n```\n\nIf you are using the\n[`std` library HTTP API](https://deno.land/manual@v1.17.2/runtime/http_server_apis)\nthen it would look something like this:\n\n```ts\nimport { createReporter } from \"https://deno.land/x/g_a/mod.ts\";\nimport { serve } from \"https://deno.land/std/http/server.ts\";\nimport type { ConnInfo } from \"https://deno.land/std/http/server.ts\";\n\nconst ga = createReporter();\n\nfunction handler(req: Request, conn: ConnInfo) {\n  let err;\n  let res: Response;\n  const start = performance.now();\n  try {\n    // processing of the request...\n    res = new Response(/* response details */);\n  } catch (e) {\n    err = e;\n  } finally {\n    ga(req, conn, res!, start, err);\n  }\n  return res!;\n}\n\nserve(handler);\n```\n\n### `createReportMiddleware()`\n\nIf you are using [oak](https://deno.land/x/oak/), then\n`createReportMiddleware()` can be used to create a middleware which will do the\njob:\n\n```ts\nimport { createReportMiddleware } from \"https://deno.land/x/g_a/mod.ts\";\nimport { Application } from \"https://deno.land/x/oak/mod.ts\";\n\nconst ga = createReportMiddleware();\nconst app = new Application();\n\napp.use(ga);\n// register additional middleware...\n\napp.listen({ port: 0 });\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenoland%2Fga","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenoland%2Fga","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenoland%2Fga/lists"}