PHPackages                             elsadany/google-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. [API Development](/categories/api)
4. /
5. elsadany/google-analytics

ActiveLibrary[API Development](/categories/api)

elsadany/google-analytics
=========================

retrive results from google analytics

0781[1 PRs](https://github.com/elsadany/analytics/pulls)PHP

Since Aug 27Pushed 7y ago2 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Google Analytics
================

[](#google-analytics)

Retrieve data from Google Analytics
-----------------------------------

[](#retrieve-data-from-google-analytics)

Using this package you can easily retrieve data from Google Analytics.

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

[](#installation)

```
composer require elsadany/google-analytics dev-master
```

```
///  config/app ->providers

Elsadany\Analytics\AnalyticsServiceProvider::class,
```

publish the config file of this package with this command:

```
php artisan vendor:publish
```

The following config file will be published in `config/analyticsConfig.php`

```
return[
    /*
     * The view id of which you want to display data.
     */
    'view_id'=>'',
/*
the path of your layout
*/
    'extend'=>'',
/*
Content Area Name
*/
    'ContentArea'=>'',
    /*
     * Path to the client secret json file. Take a look at the README of this package
     * to learn how to get this file. You can also pass the credentials as an array
     * instead of a file path.
     */
//the service key path from the root example 'public/service.json'
    'service_path'=>''
];
```

How to obtain the credentials to communicate with Google Analytics
------------------------------------------------------------------

[](#how-to-obtain-the-credentials-to-communicate-with-google-analytics)

### Getting credentials

[](#getting-credentials)

The first thing you’ll need to do is to get some credentials to use Google API’s. I’m assuming that you’ve already created a Google account and are signed in. Head over to [Google API’s site](https://console.developers.google.com/apis) and click "Select a project" in the header.

[![1](https://camo.githubusercontent.com/c2806a0a3ccb46c93b57571b245a9e4ab33fca8fc931ebb5b479e2ca9a4b0b9c/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d616e616c79746963732f76322f312e6a7067)](https://camo.githubusercontent.com/c2806a0a3ccb46c93b57571b245a9e4ab33fca8fc931ebb5b479e2ca9a4b0b9c/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d616e616c79746963732f76322f312e6a7067)

Next up we must specify which API’s the project may consume. In the list of available API’s click "Google Analytics API". On the next screen click "Enable".

[![2](https://camo.githubusercontent.com/c4e447f4779243aa4f252dcc8fbd2f69ab75778cd84f7ead0a223d90fabe54a9/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d616e616c79746963732f76322f322e6a7067)](https://camo.githubusercontent.com/c4e447f4779243aa4f252dcc8fbd2f69ab75778cd84f7ead0a223d90fabe54a9/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d616e616c79746963732f76322f322e6a7067)

Now that you’ve created a project that has access to the Analytics API it’s time to download a file with these credentials. Click "Credentials" in the sidebar. You’ll want to create a "Service account key".

[![3](https://camo.githubusercontent.com/bc2ea02a506a995d4337450c434ecd1942315607e63d306fa165abe248f0bcd6/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d616e616c79746963732f76322f332e6a7067)](https://camo.githubusercontent.com/bc2ea02a506a995d4337450c434ecd1942315607e63d306fa165abe248f0bcd6/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d616e616c79746963732f76322f332e6a7067)

On the next screen you can give the service account a name. You can name it anything you’d like. In the service account id you’ll see an email address. We’ll use this email address later on in this guide. Select "JSON" as the key type and click "Create" to download the JSON file.

[![4](https://camo.githubusercontent.com/2fff29572b2baeda063cf4513c36a6a0a46cef5aeb8dd3f0e7635e15b75d48c1/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d616e616c79746963732f76322f342e6a7067)](https://camo.githubusercontent.com/2fff29572b2baeda063cf4513c36a6a0a46cef5aeb8dd3f0e7635e15b75d48c1/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d616e616c79746963732f76322f342e6a7067)

Save the json inside your Laravel project at the location specified in the `service_account_credentials_json` key of the config file of this package. Because the json file contains potentially sensitive information I don't recommend committing it to your git repository.

### Granting permissions to your Analytics property

[](#granting-permissions-to-your-analytics-property)

I'm assuming that you've already created a Analytics account on the [Analytics site](https://analytics.google.com/analytics). Go to "User management" in the Admin-section of the property.

[![5](https://camo.githubusercontent.com/393c4779b578e29f1d1deda198520786a485f944db003c6a1290a706047e91a5/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d616e616c79746963732f76322f352e6a7067)](https://camo.githubusercontent.com/393c4779b578e29f1d1deda198520786a485f944db003c6a1290a706047e91a5/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d616e616c79746963732f76322f352e6a7067)

On this screen you can grant access to the email address found in the `client_email` key from the json file you download in the previous step. Read only access is enough.

[![6](https://camo.githubusercontent.com/40c690440f70774f0ed9134bd68eb3da0833c28e549e5981a45900ad5b15d2ee/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d616e616c79746963732f76322f362e6a7067)](https://camo.githubusercontent.com/40c690440f70774f0ed9134bd68eb3da0833c28e549e5981a45900ad5b15d2ee/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d616e616c79746963732f76322f362e6a7067)

### Getting the view id

[](#getting-the-view-id)

The last thing you'll have to do is fill in the `view_id` in the config file. You can get the right value on the [Analytics site](https://analytics.google.com/analytics). Go to "View setting" in the Admin-section of the property.

[![7](https://camo.githubusercontent.com/d5a990edaf2479efae7a76d98de4e8a573e1708f7d0edc77f99c7bfcb62fe165/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d616e616c79746963732f76322f372e6a7067)](https://camo.githubusercontent.com/d5a990edaf2479efae7a76d98de4e8a573e1708f7d0edc77f99c7bfcb62fe165/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d616e616c79746963732f76322f372e6a7067)

You'll need the `View ID` displayed there.

[![8](https://camo.githubusercontent.com/b4971e0220859ff5a4103f6d7abcfa181043d919e7a348f29d44314698929d26/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d616e616c79746963732f76322f382e6a7067)](https://camo.githubusercontent.com/b4971e0220859ff5a4103f6d7abcfa181043d919e7a348f29d44314698929d26/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d616e616c79746963732f76322f382e6a7067)

\#- /now you can get reports on /google-analytics/show

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 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/2e44daea0d27966b6331446ea73a2d39ad6b01edab0430c7f429749eabdaf58e?d=identicon)[elsadany](/maintainers/elsadany)

---

Top Contributors

[![elsadany](https://avatars.githubusercontent.com/u/18101329?v=4)](https://github.com/elsadany "elsadany (16 commits)")

### Embed Badge

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

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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