PHPackages                             gabot/gabot - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. gabot/gabot

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

gabot/gabot
===========

Google Analytics 4 Bot with PHP

2374PHP

Since Jul 4Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/bberkay/gabot)[ Packagist](https://packagist.org/packages/gabot/gabot)[ RSS](/packages/gabot-gabot/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Simple Bot with PHP for Google Analytics 4
==========================================

[](#simple-bot-with-php-for-google-analytics-4)

### Table of Contents

[](#table-of-contents)

1. [Introduction](#introduction)
2. [Installation](#installation)
3. [How to use?](#how-to-use)
4. [Report List](#ready-made-report-list)
5. [Source Code](#source-code-of-example)

Introduction
------------

[](#introduction)

Gabot 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.

Installation
------------

[](#installation)

#### What do you need?

[](#what-do-you-need)

- [GA4 Property ID](https://support.google.com/analytics/answer/12270356?hl=en#:~:text=A%20Measurement%20ID%20is%20an,same%20as%20your%20destination%20ID.)
- [Chart.js Library](https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js)
- [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.).

Download with [composer](https://getcomposer.org/Composer-Setup.exe)

```
composer require gabot/gabot:dev-master@dev

```

How to Use?
===========

[](#how-to-use)

Setup
-----

[](#setup)

```
require __DIR__.'/vendor/autoload.php'; // Composer Autoload

use Gabot\Gabot;
use Gabot\Model\Query;
use Gabot\Model\Chart; // Optional, for visualize with chart.js

$property_id = "GA4 Property ID";
$credentials_path = "./credentials.json path";
$gabot = Gabot::getInstance($property_id, $credentials_path);
```

Ready-made Reports
------------------

[](#ready-made-reports)

Gabot 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.

### Get

[](#get)

```
$reports = $gabot->getActiveUsersByOS("28daysAgo", "today");
print_r($reports->get());
```

```
[
    {
       "operatingSystem_activeUsers":[
          {
            "operatingSystem":"iOS",
            "activeUsers":"2"
          },
          {
            "operatingSystem":"Windows",
            "activeUsers":"4"
          },
          {
            "operatingSystem":"Linux",
            "activeUsers":"1"
          }
       ]
    }
 ]
```

### Visualize

[](#visualize)

```
myChart - operatingSystem_activeUsers

```

```
// Default chart settings
$reports->visualize(new Chart(chart_id:"myChart"));

// With custom chart settings
$reports->visualize(new Chart(
    chart_id:"myChart",
    chart_options:'{scales: { yAxes: [{ ticks: { beginAtZero: true } }] }, legend: {display:false}}',
    chart_type:"bar"
));
```

[![myChart](https://camo.githubusercontent.com/1614e10134d506a398662e94d8b8a710a26139b319eab5842b87ce91e2bc4c8a/68747470733a2f2f692e6962622e636f2f64474377647a4d2f6d7943686172742e706e67)](https://camo.githubusercontent.com/1614e10134d506a398662e94d8b8a710a26139b319eab5842b87ce91e2bc4c8a/68747470733a2f2f692e6962622e636f2f64474377647a4d2f6d7943686172742e706e67)

Custom Reports
--------------

[](#custom-reports)

You 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)

### Get

[](#get-1)

```
$reports = $gabot->runRequest([
    new Query(
        date_ranges:["start_date" => "28daysAgo", "end_date" => "today"],
        dimensions:["browser"],
        metrics:["activeUsers"]
    ),
    new Query(
        date_ranges:["start_date" => "28daysAgo", "end_date" => "today"],
        dimensions:["deviceCategory"],
        metrics:["activeUsers"]
    ),
    new Query(
        date_ranges:["start_date" => "28daysAgo", "end_date" => "today"],
        dimensions:["operatingSystem"],
        metrics:["activeUsers"]
    )
]);
print_r($reports->get());
```

```
[
    {
       "browser_activeUsers":[
          {
            "browser":"Chrome",
            "activeUsers":"6"
          },
          {
            "browser":"Edge",
            "activeUsers":"1"
          },
       ]
    },
    {
       "deviceCategory_activeUsers":[
          {
            "deviceCategory":"Desktop",
            "activeUsers":"5"
          },
          {
            "deviceCategory":"Mobile",
            "activeUsers":"2"
          },
       ]
    },
    {
       "operatingSystem_activeUsers":[
          {
            "browser":"Windows",
            "activeUsers":"4"
          },
          {
            "browser":"iOS",
            "activeUsers":"2"
          },
          {
            "browser":"Linux",
            "activeUsers":"1"
          },
       ]
    }
]
```

### Visualize

[](#visualize-1)

```
myChart2 - browser_activeUsers

myChart3 - deviceCategory_activeUsers

myChart4 - operatingSystem_activeUsers

```

```
$reports->visualize([
    new Chart(
        chart_id:"myChart2",
        chart_options:'{scales: { yAxes: [{ ticks: { beginAtZero: true } }] }, legend: {display:false}}',
        chart_type:"bar"
    ),
    new Chart(
        chart_id:"myChart3",
        chart_options:'{scales: { yAxes: [{ ticks: { beginAtZero: true } }] }, legend: {display:false}}',
        chart_type:"bar"
    ),
    new Chart(
        chart_id:"myChart4",
        chart_options:'{scales: { yAxes: [{ ticks: { beginAtZero: true } }] }, legend: {display:false}}',
        chart_type:"bar"
    )
]);
```

[![myChart2-myChart3-myChart4](https://camo.githubusercontent.com/986a8e934b132177276a716805ef130aa09a6fb79027de73d244840781ea9653/68747470733a2f2f692e6962622e636f2f793453443642322f6d792d43686172743233342e706e67)](https://camo.githubusercontent.com/986a8e934b132177276a716805ef130aa09a6fb79027de73d244840781ea9653/68747470733a2f2f692e6962622e636f2f793453443642322f6d792d43686172743233342e706e67)

Realtime Reports
----------------

[](#realtime-reports)

Apart 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)

### Get

[](#get-2)

```
 print_r($gabot->runRealtimeRequest(
    new Query(
        dimensions:["country"],
        metrics:["activeUsers"]
    )
)->get()); // Real-time reports can be visualized like any other.
```

```
[
    {
       "country_activeUsers":[
          {
            "country":"United States",
            "activeUsers":"4"
          },
          {
            "country":"Turkey",
            "activeUsers":"3"
          },
       ]
    }
]
```

Ready-made Report List
----------------------

[](#ready-made-report-list)

All 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.

DescriptionFunctionGet active users by devicegetActiveUsersByDevice()Get active users by operating systemgetActiveUsersByOs()Get active users by browsergetActiveUsersByBrowser()Get active users by citygetActiveUsersByCity()Get active users by countrygetActiveUsersByCountry()Get active users by country and citygetActiveUsersByCountryAndCity()Get active users by page pathgetActiveUsersByPagePath()Get active users by languagegetActiveUsersByLanguage()Get active users by first user sourcegetActiveUsersByFirstUserSource()Get active users by regiongetActiveUsersByRegion()Get active users by gendergetActiveUsersByGender()- For more information, please visit [Google Analytics Data API](https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema?hl=en)
- Also you can use [GA4 Query Explorer](https://ga-dev-tools.google/ga4/query-explorer/)

Add New Report To Gabot
-----------------------

[](#add-new-report-to-gabot)

- You can add this template to the end of the `src/Gabot.php` file, then edit it however you want.

```
/**
 * Function description
 * @param {type_of_param} param Parameter description
 * @returns {Report}
 */
public function newReport(string $start_date, string $end_date): Report
{
	return $this->runRequest([
            new Query(
                metrics: ["activeUsers"], // Metrics: https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema?hl=en#metrics
                dimensions: ["city"], // Dimensions: https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema?hl=en#dimensions
                date_ranges: ["start_date" => $start_date, "end_date" => $end_date] // Date Ranges: https://developers.google.com/analytics/devguides/reporting/data/v1/basics?hl=en#report_request
            )
        ]);
}
```

- Then you can use this `$gabot->newReport("28daysAgo", "today")->get();` way like any other ready-made report

Source Code of Example
======================

[](#source-code-of-example)

```

        Gabot Example File - Source Code

	myChart - operatingSystem_activeUsers

	myChart2 - browser_activeUsers

	myChart3 - deviceCategory_activeUsers

	myChart4 - operatingSystem_activeUsers

        getActiveUsersByOS("28daysAgo", "today");
        print_r($reports->get());

        // Default chart settings
        $reports->visualize(new Chart(chart_id:"myChart"));

        // With custom chart settings
        /*$reports->visualize(new Chart(
            chart_id:"myChart",
            chart_options:'{scales: { yAxes: [{ ticks: { beginAtZero: true } }] }, legend: {display:false}}',
            chart_type:"bar"
        ));*/

        // Custom Reports
        $result = $gabot->runRequest([
            new Query(
                date_ranges:["start_date" => "28daysAgo", "end_date" => "today"],
                dimensions:["browser"],
                metrics:["activeUsers"]
            ),
            new Query(
                date_ranges:["start_date" => "28daysAgo", "end_date" => "today"],
                dimensions:["deviceCategory"],
                metrics:["activeUsers"]
            ),
            new Query(
                date_ranges:["start_date" => "28daysAgo", "end_date" => "today"],
                dimensions:["operatingSystem"],
                metrics:["activeUsers"]
            )
        ]);

        $result->visualize([
            new Chart(
                chart_id:"myChart2",
                chart_options:'{scales: { yAxes: [{ ticks: { beginAtZero: true } }] }, legend: {display:false}}',
                chart_type:"bar"
            ),
            new Chart(
                chart_id:"myChart3",
                chart_options:'{scales: { yAxes: [{ ticks: { beginAtZero: true } }] }, legend: {display:false}}',
                chart_type:"bar"
            ),
            new Chart(
                chart_id:"myChart4",
                chart_options:'{scales: { yAxes: [{ ticks: { beginAtZero: true } }] }, legend: {display:false}}',
                chart_type:"bar"
            )
        ]);

        // Realtime Reports
        print_r($gabot->runRealtimeRequest(
           new Query(
                dimensions:["country"],
                metrics:["activeUsers"]
            )
        )->get()); // Real-time reports can be visualized like any other.
        ?>

```

---

#####

[](#berkaykayaforbusinessgmailcom)

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/18dd15bd9f78259e92bf66c813b152bdf4771402d6166b0b90fa6f6827377acf?d=identicon)[bberkay](/maintainers/bberkay)

---

Top Contributors

[![bberkay](https://avatars.githubusercontent.com/u/62906693?v=4)](https://github.com/bberkay "bberkay (87 commits)")

---

Tags

analyticschartjsgooglegoogle-analyticsgoogle-analytics-4php

### Embed Badge

![Health badge](/badges/gabot-gabot/health.svg)

```
[![Health](https://phpackages.com/badges/gabot-gabot/health.svg)](https://phpackages.com/packages/gabot-gabot)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
