{"id":22344151,"url":"https://github.com/bberkay/gabot","last_synced_at":"2025-10-30T14:47:21.945Z","repository":{"id":153387171,"uuid":"546380779","full_name":"bberkay/gabot","owner":"bberkay","description":"Google Analytics 4 Bot with Charts.js for Visualize Google Analytics Reports Easily","archived":false,"fork":false,"pushed_at":"2025-07-04T18:51:41.000Z","size":125,"stargazers_count":2,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-04T19:41:06.924Z","etag":null,"topics":["analytics","chartjs","google","google-analytics","google-analytics-4","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/bberkay.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":"2022-10-06T01:48:47.000Z","updated_at":"2025-07-04T18:51:45.000Z","dependencies_parsed_at":"2024-05-13T11:11:50.086Z","dependency_job_id":"aea0062a-46a8-4695-9de4-1d78ddc55aa6","html_url":"https://github.com/bberkay/gabot","commit_stats":null,"previous_names":["bberkay/gabot-php"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bberkay/gabot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bberkay%2Fgabot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bberkay%2Fgabot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bberkay%2Fgabot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bberkay%2Fgabot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bberkay","download_url":"https://codeload.github.com/bberkay/gabot/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bberkay%2Fgabot/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267803963,"owners_count":24146527,"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-07-30T02:00:09.044Z","response_time":70,"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":["analytics","chartjs","google","google-analytics","google-analytics-4","php"],"created_at":"2024-12-04T09:08:40.698Z","updated_at":"2025-10-30T14:47:21.852Z","avatar_url":"https://github.com/bberkay.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align = \"center\"\u003eSimple Bot with PHP for Google Analytics 4\u003c/h1\u003e\n\n\u003ch3\u003eTable of Contents\u003c/h3\u003e\n\n1. [Introduction](#introduction)\n2. [Installation](#installation)\n3. [How to use?](#how-to-use)\n4. [Report List](#ready-made-report-list)\n5. [Source Code](#source-code-of-example)\n\n## Introduction\nGabot allows users to easily retrieve their Google Analytics 4 data and use it in an integrated way with the chart.js library.  It also has the ability to create custom and/or real-time reports, along with about 11 pre-made reports, without limiting the capabilities of Google Analytics or chart.js.\n\n## Installation\n#### What do you need?\n* [GA4 Property ID](https://support.google.com/analytics/answer/12270356?hl=en#:~:text=A%20Measurement%20ID%20is%20an,same%20as%20your%20destination%20ID.)\n* [Chart.js Library](https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js)\n* [credentials.json](https://developers.google.com/analytics/devguides/reporting/data/v1/quickstart-client-libraries#step_1_enable_the_api)(this json file has contains keys like `type`, `project_id`, `private_key_id`, `private_key` etc.).\n\nDownload with [composer](https://getcomposer.org/Composer-Setup.exe)\n```\ncomposer require gabot/gabot:dev-master@dev\n```\n\n# How to Use?\n## Setup\n```php\nrequire __DIR__.'/vendor/autoload.php'; // Composer Autoload\n\nuse Gabot\\Gabot;\nuse Gabot\\Model\\Query;\nuse Gabot\\Model\\Chart; // Optional, for visualize with chart.js\n\n$property_id = \"GA4 Property ID\";\n$credentials_path = \"./credentials.json path\";\n$gabot = Gabot::getInstance($property_id, $credentials_path);\n```\n## Ready-made Reports\nGabot has some ready-made reports like getActiveUsersByOS as seen in the example, all ready-made reports are listed in [Ready Made Report List](https://github.com/bberkay/gabot/edit/master/README.md#ready-made-report-list) section.\n### Get\n```php\n$reports = $gabot-\u003egetActiveUsersByOS(\"28daysAgo\", \"today\");\nprint_r($reports-\u003eget());\n```\n```json\n[\n    {\n       \"operatingSystem_activeUsers\":[\n          {\n            \"operatingSystem\":\"iOS\",\n            \"activeUsers\":\"2\"\n          },\n          {\n            \"operatingSystem\":\"Windows\",\n            \"activeUsers\":\"4\"\n          },\n          {\n            \"operatingSystem\":\"Linux\",\n            \"activeUsers\":\"1\"\n          }\n       ]\n    }\n ]\n```\n### Visualize\n```html\n\u003ch4\u003emyChart - operatingSystem_activeUsers\u003c/h4\u003e\n\u003ccanvas id=\"myChart\" style=\"width:100%;max-width:700px\"\u003e\u003c/canvas\u003e\n\n\u003c!-- Chart.js Library --\u003e\n\u003cscript src=\"https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js\"\u003e\u003c/script\u003e\n```\n```php\n// Default chart settings\n$reports-\u003evisualize(new Chart(chart_id:\"myChart\"));\n\n// With custom chart settings\n$reports-\u003evisualize(new Chart(\n    chart_id:\"myChart\", \n    chart_options:'{scales: { yAxes: [{ ticks: { beginAtZero: true } }] }, legend: {display:false}}', \n    chart_type:\"bar\"\n));\n```\n![myChart](https://i.ibb.co/dGCwdzM/myChart.png)\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n## Custom Reports\nYou can also call your own custom reports with query object as seen in example. For more information about date_ranges, dimensions and metrics check the google analytics documentation from [here.](https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema?hl=en)\n### Get\n```php\n$reports = $gabot-\u003erunRequest([\n    new Query(\n        date_ranges:[\"start_date\" =\u003e \"28daysAgo\", \"end_date\" =\u003e \"today\"],\n        dimensions:[\"browser\"],\n        metrics:[\"activeUsers\"]\n    ),\n    new Query(\n        date_ranges:[\"start_date\" =\u003e \"28daysAgo\", \"end_date\" =\u003e \"today\"],\n        dimensions:[\"deviceCategory\"],\n        metrics:[\"activeUsers\"]\n    ), \n    new Query(\n        date_ranges:[\"start_date\" =\u003e \"28daysAgo\", \"end_date\" =\u003e \"today\"],\n        dimensions:[\"operatingSystem\"],\n        metrics:[\"activeUsers\"]\n    )\n]);\nprint_r($reports-\u003eget());\n```\n```json\n[\n    {\n       \"browser_activeUsers\":[\n          {\n            \"browser\":\"Chrome\",\n            \"activeUsers\":\"6\"\n          },\n          {\n            \"browser\":\"Edge\",\n            \"activeUsers\":\"1\"\n          },\n       ]\n    },\n    {\n       \"deviceCategory_activeUsers\":[\n          {\n            \"deviceCategory\":\"Desktop\",\n            \"activeUsers\":\"5\"\n          },\n          {\n            \"deviceCategory\":\"Mobile\",\n            \"activeUsers\":\"2\"\n          },\n       ]\n    },\n    {\n       \"operatingSystem_activeUsers\":[\n          {\n            \"browser\":\"Windows\",\n            \"activeUsers\":\"4\"\n          },\n          {\n            \"browser\":\"iOS\",\n            \"activeUsers\":\"2\"\n          },\n          {\n            \"browser\":\"Linux\",\n            \"activeUsers\":\"1\"\n          },\n       ]\n    }\n]\n```\n### Visualize\n```html\n\u003ch4\u003emyChart2 - browser_activeUsers\u003c/h4\u003e\n\u003ccanvas id=\"myChart2\" style=\"width:100%;max-width:700px\"\u003e\u003c/canvas\u003e\n\u003ch4\u003emyChart3 - deviceCategory_activeUsers\u003c/h4\u003e\n\u003ccanvas id=\"myChart3\" style=\"width:100%;max-width:700px\"\u003e\u003c/canvas\u003e\n\u003ch4\u003emyChart4 - operatingSystem_activeUsers\u003c/h4\u003e\n\u003ccanvas id=\"myChart4\" style=\"width:100%;max-width:700px\"\u003e\u003c/canvas\u003e\n```\n```php\n$reports-\u003evisualize([\n    new Chart(\n        chart_id:\"myChart2\", \n        chart_options:'{scales: { yAxes: [{ ticks: { beginAtZero: true } }] }, legend: {display:false}}', \n        chart_type:\"bar\"\n    ),\n    new Chart(\n        chart_id:\"myChart3\", \n        chart_options:'{scales: { yAxes: [{ ticks: { beginAtZero: true } }] }, legend: {display:false}}', \n        chart_type:\"bar\"\n    ),\n    new Chart(\n        chart_id:\"myChart4\", \n        chart_options:'{scales: { yAxes: [{ ticks: { beginAtZero: true } }] }, legend: {display:false}}', \n        chart_type:\"bar\"\n    )\n]);\n```\n![myChart2-myChart3-myChart4](https://i.ibb.co/y4SD6B2/my-Chart234.png)\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n## Realtime Reports\nApart from custom and ready-made reports, Gabot can also call real-time reports with query object and use them with chart.js as seen in example. For more information about realtime dimensions and metrics check the google analytics documentation from [here.](https://developers.google.com/analytics/devguides/reporting/data/v1/realtime-api-schema?hl=en)\n### Get\n```php\n print_r($gabot-\u003erunRealtimeRequest(\n    new Query(\n        dimensions:[\"country\"],\n        metrics:[\"activeUsers\"]\n    )\n)-\u003eget()); // Real-time reports can be visualized like any other.\n```\n```json\n[\n    {\n       \"country_activeUsers\":[\n          {\n            \"country\":\"United States\",\n            \"activeUsers\":\"4\"\n          },\n          {\n            \"country\":\"Turkey\",\n            \"activeUsers\":\"3\"\n          },\n       ]\n    }\n]\n```\n\u003cbr/\u003e\n\n## Ready-made Report List\nAll reports that are available in Gabot currently, if you don't have the query you're looking for, you can learn how to add your own report to the bot from the [Add New Report](https://github.com/bberkay/gabot/edit/master/README.md#add-new-report-to-gabot) section.\n| Description | Function |\n| ------------- | ------------- |\n| Get active users by device  | getActiveUsersByDevice() |\n| Get active users by operating system  | getActiveUsersByOs() |\n| Get active users by browser  | getActiveUsersByBrowser() |\n| Get active users by city  | getActiveUsersByCity() |\n| Get active users by country  | getActiveUsersByCountry() |\n| Get active users by country and city | getActiveUsersByCountryAndCity() |\n| Get active users by page path  | getActiveUsersByPagePath() |\n| Get active users by language  | getActiveUsersByLanguage() |\n| Get active users by first user source  | getActiveUsersByFirstUserSource() |\n| Get active users by region  | getActiveUsersByRegion() |\t\n| Get active users by gender | getActiveUsersByGender() |\n\n- For more information, please visit [Google Analytics Data API](https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema?hl=en)\n- Also you can use [GA4 Query Explorer](https://ga-dev-tools.google/ga4/query-explorer/)\n\u003cbr/\u003e\n\n## Add New Report To Gabot\n- You can add this template to the end of the `src/Gabot.php` file, then edit it however you want.\n```php\n/**\n * Function description\n * @param {type_of_param} param Parameter description\n * @returns {Report}\n */\npublic function newReport(string $start_date, string $end_date): Report\n{\n\treturn $this-\u003erunRequest([\n            new Query(\n                metrics: [\"activeUsers\"], // Metrics: https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema?hl=en#metrics\n                dimensions: [\"city\"], // Dimensions: https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema?hl=en#dimensions\n                date_ranges: [\"start_date\" =\u003e $start_date, \"end_date\" =\u003e $end_date] // Date Ranges: https://developers.google.com/analytics/devguides/reporting/data/v1/basics?hl=en#report_request\n            )\n        ]);\n}\n```\n- Then you can use this `$gabot-\u003enewReport(\"28daysAgo\", \"today\")-\u003eget();` way like any other ready-made report\n\u003cbr/\u003e\n\n# Source Code of Example\n```html\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003ctitle\u003eGabot Example File - Source Code\u003c/title\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n\t\u003ch4\u003emyChart - operatingSystem_activeUsers\u003c/h4\u003e\n        \u003ccanvas id=\"myChart\" style=\"width:100%;max-width:600px\"\u003e\u003c/canvas\u003e\n\t\u003cdiv style=\"display:flex\"\u003e\n\t\u003cdiv\u003e\n\t\u003ch4\u003emyChart2 - browser_activeUsers\u003c/h4\u003e\n        \u003ccanvas id=\"myChart2\" style=\"width:100%;max-width:1000px\"\u003e\u003c/canvas\u003e\n\t\u003c/div\u003e\n\t\u003cdiv\u003e\n\t\u003ch4\u003emyChart3 - deviceCategory_activeUsers\u003c/h4\u003e\n        \u003ccanvas id=\"myChart3\" style=\"width:100%;max-width:1000px\"\u003e\u003c/canvas\u003e\n\t\u003c/div\u003e\n\t\u003cdiv\u003e\n\t\u003ch4\u003emyChart4 - operatingSystem_activeUsers\u003c/h4\u003e\n        \u003ccanvas id=\"myChart4\" style=\"width:100%;max-width:1000px\"\u003e\u003c/canvas\u003e\n\t\u003c/div\u003e\n\t\u003c/div\u003e\n        \n        \u003c!-- Chart.js Library ---\u003e\n        \u003cscript src=\"https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js\"\u003e\u003c/script\u003e\n        \u003c?php \n        // Setup\n        require __DIR__.'/vendor/autoload.php'; // Composer Autoload\n\n        use Gabot\\Gabot;\n        use Gabot\\Model\\Query;\n        use Gabot\\Model\\Chart; // Optional, for visualize\n    \n        $property_id = \"GA4-Property-ID\";\n        $credentials_path = \"credentials.json\";\n        $gabot = Gabot::getInstance($property_id, $credentials_path);\n        \n        // Ready-made Reports\n        $reports = $gabot-\u003egetActiveUsersByOS(\"28daysAgo\", \"today\");\n        print_r($reports-\u003eget());\n           \n        // Default chart settings\n        $reports-\u003evisualize(new Chart(chart_id:\"myChart\"));\n\n        // With custom chart settings\n        /*$reports-\u003evisualize(new Chart(\n            chart_id:\"myChart\", \n            chart_options:'{scales: { yAxes: [{ ticks: { beginAtZero: true } }] }, legend: {display:false}}', \n            chart_type:\"bar\"\n        ));*/\n        \n        // Custom Reports\n        $result = $gabot-\u003erunRequest([\n            new Query(\n                date_ranges:[\"start_date\" =\u003e \"28daysAgo\", \"end_date\" =\u003e \"today\"],\n                dimensions:[\"browser\"],\n                metrics:[\"activeUsers\"]\n            ),\n            new Query(\n                date_ranges:[\"start_date\" =\u003e \"28daysAgo\", \"end_date\" =\u003e \"today\"],\n                dimensions:[\"deviceCategory\"],\n                metrics:[\"activeUsers\"]\n            ), \n            new Query(\n                date_ranges:[\"start_date\" =\u003e \"28daysAgo\", \"end_date\" =\u003e \"today\"],\n                dimensions:[\"operatingSystem\"],\n                metrics:[\"activeUsers\"]\n            )\n        ]);\n        \n        $result-\u003evisualize([\n            new Chart(\n                chart_id:\"myChart2\", \n                chart_options:'{scales: { yAxes: [{ ticks: { beginAtZero: true } }] }, legend: {display:false}}', \n                chart_type:\"bar\"\n            ),\n            new Chart(\n                chart_id:\"myChart3\", \n                chart_options:'{scales: { yAxes: [{ ticks: { beginAtZero: true } }] }, legend: {display:false}}', \n                chart_type:\"bar\"\n            ),\n            new Chart(\n                chart_id:\"myChart4\", \n                chart_options:'{scales: { yAxes: [{ ticks: { beginAtZero: true } }] }, legend: {display:false}}', \n                chart_type:\"bar\"\n            )\n        ]);\n        \n        // Realtime Reports\n        print_r($gabot-\u003erunRealtimeRequest(\n           new Query(\n                dimensions:[\"country\"],\n                metrics:[\"activeUsers\"]\n            )\n        )-\u003eget()); // Real-time reports can be visualized like any other.\n        ?\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\n\u003chr\u003e\n\u003ch5 align=\"center\"\u003e\u003ca href=\"mailto:berkaykayaforbusiness@gmail.com\"\u003eberkaykayaforbusiness@gmail.com\u003c/a\u003e\u003c/h5\u003e \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbberkay%2Fgabot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbberkay%2Fgabot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbberkay%2Fgabot/lists"}