PHPackages                             the-3labs-team/php-cloudflare-analytics - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. the-3labs-team/php-cloudflare-analytics

ActiveLibrary[HTTP &amp; Networking](/categories/http)

the-3labs-team/php-cloudflare-analytics
=======================================

A php package to retrieve page views and other data from Cloudflare Analytics

00[1 PRs](https://github.com/The-3Labs-Team/php-cloudflare-analytics/pulls)PHP

Since Dec 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/The-3Labs-Team/php-cloudflare-analytics)[ Packagist](https://packagist.org/packages/the-3labs-team/php-cloudflare-analytics)[ RSS](/packages/the-3labs-team-php-cloudflare-analytics/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Cloudflare Analytics GraphQL API PHP Client
===========================================

[](#cloudflare-analytics-graphql-api-php-client)

This package is a simple PHP client for the Cloudflare Analytics GraphQL API.

> ⚠️ **Note:** This package is not official and is not affiliated with Cloudflare. It is a community-driven package.

> 🚨 **Note 2:** This package is under development and is not ready for production.

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

[](#installation)

You can install the package via composer:

```
composer require the-3labs-team/php-cloudflare-analytics
```

Configuration
-------------

[](#configuration)

Add in your .env file the following variables:

```
CLOUDFLARE_API_TOKEN='your_cloudflare_api_token'
CLOUDFLARE_ZONE_TAG_ID='zoneTag'
```

or you can pass the token and zoneTag as parameters in the constructor.

```
use The3LabsTeam\PhpCloudflareAnalytics\CloudflareAnalytics;

$cf = new CloudflareAnalytics(
    token: 'your_cloudflare_api_token', zoneTag: 'zoneTag'
);
```

Usage
-----

[](#usage)

You can use the following methods to build your query:

```
use The3LabsTeam\PhpCloudflareAnalytics\CloudflareAnalytics;

$cf = new CloudflareAnalytics;

$results = $cf->select('firewallEventsAdaptive AS firewall')
    ->get('firewall.datetime', 'firewall.action');
```

The `get` method will return an array with the results.

Available fields
----------------

[](#available-fields)

- `firewallEventsAdaptive`
- `httpRequests1mGroups`
- `httpRequestsAdaptiveGroups`
- `threatsAdaptiveGroups`
- `threatsByCountryAdaptiveGroups`

Default fields
--------------

[](#default-fields)

- `datetime`: 1 hour
- `take`: 10
- `orderBy`: `datetime`

Demo
----

[](#demo)

Get latest 10 firewall events:

```
$results = $cf->select('firewallEventsAdaptive AS firewall')
    ->get('firewall.datetime', 'firewall.action');
```

Filter between two dates:

```
$results = $cf->select('firewallEventsAdaptive AS firewall')
    ->where('firewall.datetime', '>=', '2021-10-01T00:00:00Z')
    ->where('firewall.datetime', '
