PHPackages                             benemohamed/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. benemohamed/analytics

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

benemohamed/analytics
=====================

Google Analytics library for PHP

v1.0.0(6y ago)32Apache-2.0PHPPHP ^7.1CI failing

Since Jul 2Pushed 6y ago1 watchersCompare

[ Source](https://github.com/benemohamed/google-analytics-php)[ Packagist](https://packagist.org/packages/benemohamed/analytics)[ Docs](https://github.com/benemohamed)[ RSS](/packages/benemohamed-analytics/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

Google Analytics library PHP
============================

[](#google-analytics-library-php)

Google Analytics library for:

- Analyze your API
- Analyze your image and other file type
- Analyze all server
- Analyze the user how block `127.0.0.1 google-analytics.com 127.0.0.1 www.google-analytics.com`

Getting Started
---------------

[](#getting-started)

- See the [Measurement Protocol Parameter Reference](https://developers.google.com/analytics/devguides/collection/protocol/v1/reference).

Requirements
------------

[](#requirements)

- PHP &gt;= 7.1
- JSON PHP Extension
- CURL PHP Extension
- GMP PHP Extension

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

[](#installation)

Installing Google Analytics library using Composer:

```
composer require benemohamed/analytics
```

How to Use
----------

[](#how-to-use)

usage is quite simple:

```
require __DIR__ .'/vendor/autoload.php';
// import
use benemohamed\analytics\Analytics;

$analytics = new Analytics('UA-101958632-2',null);
// null = free TOKEN from https://ipfinder.io or sign up to get your free token ipfinder.io/auth/signup
// UA-101958632-2 = your The tracking ID / web property ID

// The hit type is pageview
$test->send();
```

> with default we set User agent,user IP,Geographical Override,hostname,path,title

> include this file

work with available methods
---------------------------

[](#work-with-available-methods)

```
require __DIR__ .'/vendor/autoload.php';
// import
use benemohamed\analytics\Analytics;

$analytics = new Analytics('TRACKING_ID_GOES_HERE','YOUR_IPFINDER_TOKEN_GOES_HERE');

$analytics->set_uagt('dsadasdasdasdsadasd') // User agent
                ->set_hit('pageview')   // Set Hit Type
                ->set_ip('9.9.9.9')    // user IP
                ->set_location('GB')   //  Geographical Override
                ->set_host('google.com')  // hostname
                ->set_path('/hello-world') // The path portion of the page URL. Should begin with '/'.
                ->set_title('hello world - Mohamed ') // The title of the page
                ->set_event_tra('server')         //  Event Tracking
                ->set_event_act('user block')     //  Event Action
                ->set_event_lab('test')           //  Event Action
                ->parms(array(
                     'dr' => 'http://example.com', // Document Referrer
                     'cn' => '(soical)',           // Campaign Name
                     'cm' => 'organic'             // Campaign Medium
                 ))
                ;

$analytics->send(); // make the call to the server
```

Work with only method `parms(array())`
--------------------------------------

[](#work-with-only-method-parmsarray)

lists all of the parameters for the [Measurement Protocol](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#dl).

> Note check Required parameters

```
require __DIR__ .'/vendor/autoload.php';
// import
use benemohamed\analytics\Analytics;

$analytics = new Analytics('TRACKING_ID_GOES_HERE','YOUR_IPFINDER_TOKEN_GOES_HERE');

$analytics-> ->parms(array(
                     'v' => 1,
                     'tid' => 'UA-101958632-2',
                     't' => 'pageview'
                     ......
                     ......
                     ......
                     ......
                     ......
                     ......
                 ));

$analytics->send(); // make the call to the server
```

Work with php.ini
-----------------

[](#work-with-phpini)

[open\_basedir](http://php.net/open-basedir)

```
php -d open_basedir=file_name
```

file\_name now in all file

Work with javascript
--------------------

[](#work-with-javascript)

**check if google-analytics.com is load in the client side if not make your action in server side**

Error handling
--------------

[](#error-handling)

```
$analytics = new Analytics('TRACKING_ID_GOES_HERE','YOUR_IPFINDER_TOKEN_GOES_HERE');

try {
    // do something
} catch (AnalyticsException $e) {
    print $e->getMessage();
}
```

List methods
------------

[](#list-methods)

```
$analytics = new Analytics('UA-101958632-2',null);

var_dump(get_class_methods($analytics));
```

NameDescriptionset\_hitSet Hit Typeset\_dsSet Data source e.x(`web`)set\_ipSet IP address e.x(`1.1.1.1`)set\_uagtSet User Agent e.x(`Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/75.0.3770.90 Chrome/75.0.3770.90 Safari/537.3`)set\_locationSet Geographical e.x(`DZ`,`MA`,`TN`)set\_hostSet hostname e.x(`google.com`)set\_pathSet path start with `/`set\_titleSet title e.x(`google.com`)set\_event\_traSet Event trackingset\_event\_actSet Event Actionset\_event\_labSet Event Labelset\_parmsSet your ParametersSupported Hits
--------------

[](#supported-hits)

- pageview
- event
- screenview
- transaction
- item
- social
- exception
- timing

**use method `parms(array())` method to pass Required Parameter to other hits**

Running the tests
-----------------

[](#running-the-tests)

```
composer test
```

other
-----

[](#other)

- See the [IPFidner documentation](https://ipfinder.io/docs).
- See the [guzzlephp documentation](http://docs.guzzlephp.org/en/stable/quickstart.html)

License
-------

[](#license)

---

[![GitHub license](https://camo.githubusercontent.com/0a25384350d949cc533cc2e9a7141b6d8f48bb048cda780faf9b37e28315aaf6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622e636f6d2f62656e656d6f68616d65642f676f6f676c652d616e616c79746963732d7068702e737667)](https://github.com/benemohamed/google-analytics-php/blob/master/LICENSE)

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2508d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/db4d82e2ed499d8612455b6287c8d40497879e02b27319a677ce9d4e7c0dd885?d=identicon)[benemohamed](/maintainers/benemohamed)

---

Tags

googlelibraryanalytics

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-analytics

A Laravel package to retrieve Google Analytics data.

3.2k5.7M57](/packages/spatie-laravel-analytics)[panphp/pan

A simple, lightweight, and privacy-focused product analytics php package.

1.2k94.6k5](/packages/panphp-pan)[lexik/data-layer-bundle

Manipulate the Google Tag Manager Data Layer from your Symfony application.

14114.2k](/packages/lexik-data-layer-bundle)[cybercog/yii2-google-analytics

Google Analytics Widget for the Yii2 framework

1677.1k2](/packages/cybercog-yii2-google-analytics)

PHPackages © 2026

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