Download the PHP package teodoriu/laravel-analytics without Composer
On this page you can find all versions of the php package teodoriu/laravel-analytics. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-analytics
Retrieve data from Google Analytics
Using this package you can easily retrieve data from Google Analytics (GA4).
Here are a few examples of the provided methods:
Installation
This package can be installed through Composer.
Add in your .env
Optionally, you can publish the config file of this package with this command:
The following config file will be published in config/analytics.php
How to obtain the credentials to communicate with Google Analytics
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 and click "Select a project" in the header.
Next up we must specify which API’s the project may consume. In the list of available API’s click "Google Analytics Data API". On the next screen click "Enable".
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".
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.
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
I'm assuming that you've already created a Analytics account on the Analytics site. Go to "User management" in the Admin-section of the property.
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.
Getting the property id
The last thing you'll have to do is fill in the property_id
in the config file. You can get the right value on the Analytics site. Go to "Property Settings" in the Admin-section of the property.
You'll need the PROPERTY ID
displayed there.
Usage
All other Google Analytics queries
To perform all other queries on the Google Analytics resource use runReport
. Google Analytics Data API (GA4) provides more information on which metrics and dimensions might be used.
API Dimensions & Metrics that are available
You can get access to the underlying BetaAnalyticsDataClient
object:
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Freek Van der Herten
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-analytics with dependencies
google/analytics-data Version ^0.4
laravel/framework Version ^6.0|^7.0|^8.0
nesbot/carbon Version ^2.0