PHPackages                             funnydevjsc/google-analytic-laravel-integrate - 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. funnydevjsc/google-analytic-laravel-integrate

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

funnydevjsc/google-analytic-laravel-integrate
=============================================

Laravel package for GA4

1.1.5(3mo ago)3195↓100%MITPHPPHP ^8.1|^8.2|^8.3|^8.4

Since May 13Pushed 3mo agoCompare

[ Source](https://github.com/funnydevjsc/google-analytic-laravel-integrate)[ Packagist](https://packagist.org/packages/funnydevjsc/google-analytic-laravel-integrate)[ Docs](https://github.com/funnydevjsc/google-analytic-laravel-integrate)[ RSS](/packages/funnydevjsc-google-analytic-laravel-integrate/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (8)Versions (17)Used By (0)

Google Analytic Laravel
=======================

[](#google-analytic-laravel)

The free Laravel package to help you integrate data with GA4

Use Cases
---------

[](#use-cases)

- Crawl and parse result from GA4 with reformated and sorted values
- Easy to understand and draw charts
- Example crawler command
- Send data to Google Analytics by Measurement Protocol.

Features
--------

[](#features)

- Dynamic Google Service credentials from config/google-service.php
- Dynamic Google Analytic properties from config/google-analytic.php
- Easy to crawl data with a simple line code
- Easy to sync your users or products and orders to Google Analytics.

Know issues
-----------

[](#know-issues)

- This package uses the latest official SDK, libraries and methods from Google then it might be large (around 30mb for dependency package google/apiclient) for shared hosting.
- Please consider your server's environment before using this package.
- However, we still recommend that you follow the latest writing style for Google libraries to ensure safety, compliance, CI/CD and most importantly if you are using services

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

[](#requirements)

- **PHP**: 8.1 or higher
- **Laravel** 9.0 or higher

Testing
-------

[](#testing)

Run unit tests for this package:

```
composer install
./vendor/bin/phpunit
```

Quick Start
-----------

[](#quick-start)

If you prefer to install this package into your own Laravel application, please follow the installation steps below

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

[](#installation)

#### Step 1. Install a Laravel project if you don't have one already

[](#step-1-install-a-laravel-project-if-you-dont-have-one-already)

#### Step 2. Require the current package using composer:

[](#step-2-require-the-current-package-using-composer)

```
composer require funnydevjsc/google-analytic-laravel-integrate
```

#### Step 3. Publish the controller file and config file

[](#step-3-publish-the-controller-file-and-config-file)

```
php artisan vendor:publish --provider="FunnyDev\GoogleAnalytic\GoogleAnalyticServiceProvider" --tag="google-analytic"
```

If publishing files fails, please create corresponding files at the path `config/google-analytic.php` and `config/google-service.php` and `app\Console\Commands\GoogleAnalyticCommand.php` from this package. And you can also further customize the GoogleAnalyticCommand.php file to suit your project.

#### Step 4. Create a Google Service credentials:

[](#step-4-create-a-google-service-credentials)

- Go to [https://console.cloud.google.com/iam-admin/serviceaccounts?hl=en&amp;project=your\_google\_project\_id](https://console.cloud.google.com/iam-admin/serviceaccounts?hl=en&project=your_google_project_id) to create a Google Service account.
- Go to [https://console.cloud.google.com/iam-admin/serviceaccounts/details/your\_google\_service\_account\_id/keys?hl=en&amp;project=your\_google\_project\_id](https://console.cloud.google.com/iam-admin/serviceaccounts/details/your_google_service_account_id/keys?hl=en&project=your_google_project_id) to create a JSON private key file like this:

[![](screenshots/google-service-account-sample.png)](screenshots/google-service-account-sample.png)

- Then download it to your computer as `application_default_credentials.json` and move it to the storage\_path of Laravel project but don't forget to ignore it from git to secure your project.

#### Step 5. Update the various config settings in the published config file:

[](#step-5-update-the-various-config-settings-in-the-published-config-file)

- After publishing the package assets a configuration file will be located at `config/google-analytic.php` and `config/google-service.php`.
- Please use your Google Service credentials values from `application_default_credentials.json` to fill into `config/google-service.php` file.
- Find your Analytic Property ID and fill into `config/google-analytic.php` file like this:

[![](screenshots/google-analytic-dashboard-sample.png)](screenshots/google-analytic-dashboard-sample.png)

- Then in this case our Analytic Property ID is `281673130` which was shown on the current URL.

#### Step 6. Add middleware protection:

[](#step-6-add-middleware-protection)

###### app/Http/Kernel.php

[](#apphttpkernelphp)

```
