Download the PHP package spatie/analytics-statistics without Composer

On this page you can find all versions of the php package spatie/analytics-statistics. 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 analytics-statistics

Analytics Statistics: Retrieve data from Google Analytics

Latest Version Build Status Quality Score Total Downloads

An opinionated package to retrieve Google Analytics data. Compatible with PHP >= 5.3.

If you're using laravel 5, check out our laravel-analytics package!

Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Postcardware

You're free to use this package (it's MIT-licensed), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

The best postcards will get published on the open source page on our website.

Install

This package can be installed through Composer.

How to obtain the credentials to communicate with Google Analytics

If you haven't already done so, set up a Google Analytics property and install the tracking code on your site.

This package needs valid configuration values for siteId, clientId and serviceEmail. Additionally a p12-fileis required.

To obtain these credentials start by going to the Google Developers Console.

If you don't have a project present in the console yet, create one. If you click on the project name, you'll see a menu item APIs under APIs & auth on the left hand side. Click it to go the the Enabled API's screen. On that screen you should enable the Analytics API. Now, again under the APIs & Auth-menu click Credentials. On this screen you should press Create new Client ID. In the creation screen make sure you select application type Service Account and key type P12-key.

This wil generate a new public/private key pair and the .p12-file will get downloaded to your machine. Store this file in the location specified in the configfile of this package.

In the properties of the newly created Service Account you'll find the values for the serviceEmail and clientId listed as CLIENT ID and EMAIL ADDRESS.

To find the right value for siteId log in to Google Analytics go the the Admin section. In the property-column select the website name of which you want to retrieve data, then click View Settings in the View-column. The value presented as View Id prepended with 'ga:' can be used as siteId.

Make sure you've added the ANALYTICS_SERVICE_EMAIL to the Google Analytics Account otherwise you will get a 403: User does not have any Google Analytics Account error. You can read Google's instructions here.

If you want to use the realtime methods you should request access to the beta version of Google's Real Time Reporting API.

Usage

Setup

The easiest way to set up Analytics is via the factory method \Spatie\Analytics\Analytics::create(). The create method requires the following parameters:

You can optionally add some extra parameters to set up caching:

Note: If you want to use a cache, you'll need to write your own implementation/adapter using the \Spatie\Analytics\Analytics\Cache interface.

Example

When the setup is done you can easily retrieve Analytics data. Methods generally return a plain array.

Here is an example to retrieve visitors and pageview data for the last seven days.

Here's another example to get the 20 most visited pages of the last 365 days

Provided methods

Visitors and pageviews

These methods return an array with columns "date", "vistors" and "pageViews". When grouping by yearMonth, the first column will be called "yearMonth".

Keywords

These methods return an array with columns "keyword" and "sessions".

Referrers

These methods return an array with columns "url" and "pageViews".

Browsers

These methods return an array with columns "browser" and "sessions".

If there are more used browsers than the number specified in maxResults, then a new resultrow with browser-name "other" will be appended with a sum of all the remaining browsers.

Most visited pages

These methods return an array with columns "url" and "pageViews".

Currently active visitors

This method uses the Real Time Reporting API. It returns the amount of visitors that is viewing your site right now.

All other Google Analytics Queries

To perform all other GA queries use . Google's Core Reporting API provides more information on on which metrics and dimensions might be used.

Testing

Run the tests with:

Contributing

Please see CONTRIBUTING for details.

Security

If you've found a bug regarding security please mail [email protected] instead of using the issue tracker.

Credits

About Spatie

Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

License

The MIT License (MIT). Please see License File for more information.


All versions of analytics-statistics with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
google/apiclient Version 1.1.*
nesbot/carbon Version ^1.19
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 spatie/analytics-statistics contains the following files

Loading the files please wait ....