Download the PHP package gtmassey/laravel-analytics without Composer

On this page you can find all versions of the php package gtmassey/laravel-analytics. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-analytics

Analytics

Latest Version on Packagist Total Downloads Tests

Build Google Analytics Data API queries in Laravel with ease!

Methods currently return an instance of Gtmassey\LaravelAnalytics\ResponseData, containing the dimension and metric headers, and results in rows.

Table of Contents:

Installation

Via Composer

Setup

To use this package, you must have a Google Cloud Service Accounts Credential.

If you do not have a project set up on Google Cloud Platform, visit console.cloud.google.com/projectcreate to create a new project.

Once you have a project, make sure you have selected that project in the top left corner of the console.

Screen Shot 2022-11-30 at 2 22 35 PM

Select APIs & Services from the quick access cards on the dashboard.

Screen Shot 2022-11-30 at 2 22 54 PM

Make sure you have Google Analytics Data API enabled. NOTE: this is NOT the same API as Google Analytics API. The Data API is the required API for this package. If you do not have the Google Analytics Data API enabled, you can add it to your Cloud Console account by clicking "enable APIs and Services"

Screen Shot 2022-11-30 at 2 23 25 PM

You can search for the Google Analytics Data API and enable it through the Google API Library

Screen Shot 2022-11-30 at 2 24 09 PM

Screen Shot 2022-11-30 at 2 24 21 PM

Once enabled, select the Google Analytics Data API from the list of APIs, and click the Credentials tab.

Screen Shot 2022-11-30 at 2 24 48 PM

If you already have a service account set up with this API, you can skip the next step.

Click the Create Credentials button, and select Service Account.

Screen Shot 2022-11-30 at 2 26 24 PM

Select the role you want to assign to the service account. For this package, the minimum role is the Viewer role.

Once your service account has been created, click on the account to go to the IAM & Admin section of Google Cloud Console.

In the Service Accounts section of the IAM & Admin page, select the appropriate service account, and create a new JSON key for the account:

Screen Shot 2022-11-30 at 2 27 01 PM

Screen Shot 2022-11-30 at 2 27 14 PM

Once the key is created, download the JSON file and save it somewhere safe. You will need this file to use this package. If you lose this file, you will have to create a new service account. Google does not let you re-issue keys.

You can use these credentials in several ways:

As ENV value (default)

This is ideal setup if you're using only one service account for your application.

Specify the path to the JSON file in your .env file:

As a separate JSON file

If you have multiple service accounts, you can instruct this package to use a specific one:

As a JSON string

If you don't want to store the credentials in a file, you can specify the JSON string directly in your .env file:

As separate values

You can also specify the credentials as separate values in your .env file:

Warning Package will always prioritize GOOGLE_APPLICATION_CREDENTIALS env value over other options. If you want to use a separate service account, make sure to set ANALYTICS_CREDENTIALS_USE_ENV=false.

Finally, open Google Analytics, and copy the property ID for the property you want to query. You will need this ID to use this package.

Screen Shot 2022-11-30 at 2 40 42 PM

Set the property ID in your .env file.

Now you're ready to start!

Usage

Once installation is complete, you can run Google Analytics Data API queries in your application.

All Google Analytics Data API queries require a date range to be run. Use the Period class to generate a period of time for the query.

Query Builder:

Filtering:

Filtering closely follows Google Analytics Data API documentation, but is built with a bit of convenience and fluid interface in mind. You can filter your query by using dimensionFilter() and metricFilter() methods. These methods accept a callback that receives an instance of Gtmassey\LaravelAnalytics\Request\Filters\FilterExpression class. The class provides a set of methods to build your filter:

You can check Gtmassey\LaravelAnalytics\Request\Filters\Filter class for a list of available filter callback methods.

Examples:

filter() method:
filterDimension() method:

Using this method you can utilize Dimensions class to fluently build your filter without having to know the exact dimension name that's used in the API.

filterMetric() method:

Similar to filterDimension() method, you can use this method and utilize Metrics class to fluently build your filter without having to know the exact metric name that's used in the API.

not() method:
andGroup() method:
orGroup() method:
Advanced example:

You can mix all of the above methods to build a complex filter expression.

Default Reports:

getTopEvents()

This method returns the top events for the given period. It accepts a Gtmassey\Period\Period object as an optional parameter.

If a Gtmassey\Period\Period object is not passed, it will use the default period set in Gtmassey\Period\Period::defaultPeriod().

The method will return an instance of Gtmassey\LaravelAnalytics\Response\ResponseData, which contains DimensionHeaders, MetricHeaders, Rows, and additional metadata.

example output:

getTopPages()

This method returns the top pages for the given period. It accepts a Gtmassey\Period\Period object as an optional parameter.

The pages along with the sessions for that page are listed in the Rows property of the response.

getUserAcquisitionOverview()

This method returns the user acquisition overview for the given period. It accepts a Gtmassey\Period\Period object as an optional parameter.

The method will return a ResponseData object with the number of sessions by the session's primary acquisition source. Primary acquisition sources are either "direct", "Referral", "Organic Search", and "Organic Social".

getUserEngagement()

This method returns a ResponseData object without dimensions. The query only contains metrics. The ResponseData object will contain:

Extensibility:

Custom metrics and dimensions:

You are not limited to the metrics and dimensions provided by this package. You can use any custom metrics and dimensions you have created in Google Analytics.

Create a new class that extends Gtmassey\LaravelAnalytics\Request\CustomMetric or Gtmassey\LaravelAnalytics\Request\CustomDimension and implement methods following this format:.

Bind the class in your AppServiceProvider:

Now you can use the custom metric in your query:

Reusable filters:

You can create reusable filters to use in your queries. Create a new class that extends Gtmassey\LaravelAnalytics\Analytics and implement methods following this format:

Bind the class in your AppServiceProvider:

Now you can use the custom filter in your query:

Change log

Read CHANGELOG.md

Testing

To run tests, run:

Note that this command also runs code coverage analysis.

Contributing

Check out the contributing guide

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

Special thanks to Plytas for their early and significant contributions to the project. Without their help setting things up and their willingness to teach me new tools and techniques, this project would be dead in its tracks.

And a huge thanks to the team over at Spatie for their continued contributions to the open source community! Some of their work is used in this project, and I have used their packages as a foundation for projects for years.

License

MIT. Please see the license file for more information.


All versions of laravel-analytics with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1|^8.2|^8.3
google/analytics-data Version ^v0.9.0
gtmassey/period Version ^1.2.0
illuminate/support Version ^10.0|^11.0
nesbot/carbon Version ^2.63
spatie/laravel-data Version ^3.12
spatie/laravel-package-tools Version ^1.13
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package gtmassey/laravel-analytics contains the following files

Loading the files please wait ....