{"id":21055311,"url":"https://github.com/quintsys/analytics-viewdata","last_synced_at":"2025-08-09T03:05:27.028Z","repository":{"id":163713236,"uuid":"636736495","full_name":"quintsys/analytics-viewdata","owner":"quintsys","description":"Pulls data from a Google Analytics view.","archived":false,"fork":false,"pushed_at":"2023-08-01T23:47:32.000Z","size":191,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-11T06:08:58.562Z","etag":null,"topics":["firebase-functions","firebase-hosting","google-analytics-api","swagger","typescript"],"latest_commit_sha":null,"homepage":"","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/quintsys.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2023-05-05T14:21:17.000Z","updated_at":"2023-05-10T22:55:32.000Z","dependencies_parsed_at":"2024-08-17T03:01:47.086Z","dependency_job_id":null,"html_url":"https://github.com/quintsys/analytics-viewdata","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/quintsys/analytics-viewdata","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quintsys%2Fanalytics-viewdata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quintsys%2Fanalytics-viewdata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quintsys%2Fanalytics-viewdata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quintsys%2Fanalytics-viewdata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quintsys","download_url":"https://codeload.github.com/quintsys/analytics-viewdata/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quintsys%2Fanalytics-viewdata/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269523360,"owners_count":24431614,"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-08-09T02:00:10.424Z","response_time":111,"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":["firebase-functions","firebase-hosting","google-analytics-api","swagger","typescript"],"created_at":"2024-11-19T16:42:59.595Z","updated_at":"2025-08-09T03:05:26.908Z","avatar_url":"https://github.com/quintsys.png","language":"TypeScript","readme":"# Google Analytics View Data\nThis project integrates with the [Google Analytics Core Reporting API][api] to\nextract metrics from a predefined View. The response will contain metrics\nextracted from the Google Analytics view data, and each record will be\nassociated with a given [`clientId`][cid].\n\n## Configuration\n\nThis project uses the built-in environment configuration offered by the Firebase\nSDK for Cloud Functions to make it easy to store and retrieve additional\nsettings.\n\nMore information at https://firebase.google.com/docs/functions/config-env\n\n### Environment variables\nBefore running the Cloud Function, the following environment variables must be\npresent:\n\n| Name          | Value  | Required | Summary                                 |\n|---------------|--------|----------|-----------------------------------------|\n| GA_VIEW_ID    | string | yes      | The unique table ID of the form `ga:XXXX`, where `XXXX` is the Analytics view (profile) ID for which the query will retrieve the data.|\n| GA_START_DATE | string | no       | Start date for fetching Analytics data.\u003cbr /\u003e Requests can specify a start date formatted as `YYYY-MM-DD`, or as a relative date (e.g., `today`, `yesterday`, or `NdaysAgo` where `N` is a positive integer).\u003cbr /\u003e Defaults to `3daysAgo`. |\n| GA_END_DATE   | string | no       | End date for fetching Analytics data.\u003cbr /\u003e Request can specify an end date formatted as `YYYY-MM-DD`, or as a relative date (e.g., `today`, `yesterday`, or `NdaysAgo` where `N` is a positive integer).\u003cbr /\u003e Defaults to `today`. |\n\nTo set these environment variables, create a `.env` file in the `/functions`\nfolder with the desired variable values. For example:\n\n```bash\nGA_VIEW_ID=ga:123456\nGA_START_DATE=yesterday\nGA_END_DATE=today\n```\n\nWhen deploying your functions using the Firebase CLI, the variables from the\n`.env` file will be automatically loaded. Run the following command to deploy\nthe functions:\n\n```bash\nfirebase deploy --only functions\n# ...\n# i functions: Loaded environment variables from .env.\n# ...\n```\n\n### Secrets\nThe following secret needs to be stored in Cloud Secret Manager:\n\n| Name            | Value  | Required | Summary                               |\n|-----------------|--------|----------|---------------------------------------|\n| GA_SVC_ACCOUNT  | string | yes      | Service account key for Analytics API |\n| GA_BEARER_TOKEN | string | yes      | Bearer token for authorization        |\n\n\nTo set the secret, use the following command:\n\n```bash\nfirebase functions:secrets:set --data-file ./svc-account.json GA_SVC_ACCOUNT\nfirebase functions:secrets:set GA_BEARER_TOKEN your_bearer_token\n```\n\nReplace `./svc-account.json` with the path to your service account key file, and\n`your_bearer_token` with the correspondent value.\n\nEnsure that you have the necessary permissions to manage secrets in Cloud\nSecret Manager.\n\nOnce the secret is set, the Firebase Functions runtime will automatically load\nit when running the functions.\n\nMake sure to set all the required environment variables and secrets before\nrunning your Cloud Function to ensure proper functionality.\n\n\n## Usage\nTo run the Cloud Function, execute the following command in your terminal:\n\n```bash\nfirebase serve --only functions\n```\n\nThis will start a local development server and you can trigger the Cloud\nFunction using an HTTP request to\nhttp://localhost:5000/{your-project-id}/{location}/gaViewData\n\nWhen making the HTTP request, ensure that the following headers are included:\n\n- Authorization: The Authorization header should follow the format Bearer\n {token}, where {token} is the actual bearer token value. This header is\n required to authenticate and authorize the request.\n\nHere's an example of how the headers should look when making an HTTP request to\nthe Cloud Function:\n\n```http\nGET /{your-project-id}/{location}/gaViewData HTTP/1.1\nHost: localhost:5000\nAuthorization: Bearer {token}\n```\n\nReplace {your-project-id} with your actual Firebase project ID and {location}\nwith the appropriate Cloud Functions location.\n\nTo deploy the Cloud Function to production, run:\n\n```bash\nfirebase deploy --only functions\n```\n\n## Response Data\n\nThe Cloud Function will return a JSON object containing an array of records,\nwith each record having the following fields:\n\n| Field           | Type   | Description                                      |\n|-----------------|--------|--------------------------------------------------|\n| clientId        | string | The unique client ID associated with the record. |\n| adGroup         | string | The name of the ad group that served the ad.     |\n| adContent       | string | For Google Ads traffic, this will be the first line of the Ad. For Microsoft and other non-Google Ads, it is the equivalent of the `adGroup` field. |\n| adMatchedQuery  | string | The search query that matched the ad.            |\n| campaign        | string | The name of the campaign that served the ad.     |\n| source          | string | The source of the traffic.                       |\n| medium          | string | The medium of the traffic.                       |\n| keyword         | string | The keyword used in the search.                  |\n\n\nHere's an example response object:\n\n```json\n{\n  \"data\": [\n    {\n      \"clientId\": \"1234.5678\",\n      \"adGroup\": \"Ad Group 1\",\n      \"adContent\": \"Content 1\",\n      \"adMatchedQuery\": \"Keyword 1\",\n      \"campaign\": \"Campaign 1\",\n      \"source\": \"google\",\n      \"medium\": \"cpc\",\n      \"keyword\": \"Keyword 1\",\n    },\n    {\n      \"clientId\": \"5678.1234\",\n      \"adGroup\": \"Ad Group 2\",\n      \"adContent\": \"Ad Group 2\",\n      \"adMatchedQuery\": \"Keyword 2\",\n      \"campaign\": \"Campaign 2\",\n      \"source\": \"bing\",\n      \"medium\": \"cpc\",\n      \"keyword\": \"Keyword 2\",\n    }\n  ]\n}\n```\n\n## Contributing\nContributions to this project are welcome. Please open a pull request with your\nchanges.\n\n## License\nThis project is licensed under the [MIT License][mit].\n\n[api]: https://developers.google.com/analytics/devguides/reporting/core/v3/\n[cid]: https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#clientId\n[mit]: https://opensource.org/licenses/MIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquintsys%2Fanalytics-viewdata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquintsys%2Fanalytics-viewdata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquintsys%2Fanalytics-viewdata/lists"}