Download the PHP package sherin/google-analytics without Composer

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

PHP 7 - Google Analytics Reporting Api v4 wrapper

Table of Contents

Installation

Requirements:

Installation Implementation in existing project with composer:

$ composer require sherin/google-analytics

Or you can start from scratch:

$ mkdir google-analytics-api
$ cd google-analytics-api
$ composer init
$ composer require sherin/google-analytics

Its not recommended/not supported to use this package without composer. It won't be documented.

Usage

This library is based on PHP 7.0 strict typing. Also we are using Doctrine's ArrayCollection because of the extra features.

All the libraries classes are wrapped inside the namespace: sherin\google\analytics\

Workflow:

  1. Login to the Google api using the Client and Credentials classes.
  2. Determine what data you want and build the query using the QueryBuilder.
  3. If you have multiple queries, create a Batch object so the requests can be send in chunks of 5 (max allowed by Google).
  4. Collect the response from Google, its possible to get JSON data or use the PHP objects.

Getting started

If you already know what Service Credentials are and you already own a json file, you can continue at step 2

  1. First you need to obtain Service Credentials from Google from THIS link.
    • Create a new project or use an existing project in the IAM and admin page.
    • Then create a new Service Account and enter a name you want (for example WebsiteService or PHPService)
    • Give the service account the role "Viewer" or "Owner". Depends if you will use other Google Libraries (you can use this key for almost all google api's)
    • When you're on Step 3 click on the [+ create key] button and select the JSON type and click [create]. Now a JSON file will be downloaded and that's your credentials file that we need.
    • After that, go to API's and services and open the Library. Search for "Google Analytics Reporting API" and enable the API for your account.
    • For now its recommended to move the JSON array to your .env file because you should NEVER commit private keys to git. You can find an example here.
  2. First we need to create a new Credentials class that contains your credentials. You can use the setters to setup your credentials or you can use the setFromArray function. The setFromArray function requires the following array setup:

And the getGoogleCredentials()function example:

  1. Now you have created the Credentials class with the required authentication tokens. Now we can start create a Client.

The following is only required if you already have a class called Client You might have a duplicate declaration Client (if you use Guzzle for example). So instead of importing (use) the class. Call it from the namespace.

  1. And finally, we create a instance of the Analytics api class so we can create requests to Google. We need this instance later.

Or if you can't use/import the class, use the following:

Limitations

The currently limitations:

  1. This library only supports Service Applications (aka Server to Server) currently.
  2. For now, a metric filter on a segment is not supported, only dimensions.

    Testing

    Testing is not added yet! FYI: PHPUnit will be used for unit testing

    Support

    You can use the issue tracker of this project to create issues. Use stackoverflow for supporting issues. The issue tracker is only for bugs reports and feature requests. (TODO ISSUE_TEMPLATE.md)

    Licence

    This project is licensed under the Apache License - see the LICENSE.md file for details


All versions of google-analytics with dependencies

PHP Build Version
Package Version
Requires google/apiclient Version ^2.0
doctrine/collections Version ^1.4
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 sherin/google-analytics contains the following files

Loading the files please wait ....