Download the PHP package slm/google-analytics without Composer

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

SlmGoogleAnalytics

Build Status Latest Stable Version Scrutinizer Code Quality

Created by Jurian Sluiman

Introduction

SlmGoogleAnalytics is a Zend Framework 2 module that enables integration with Google Analytics.

It helps to provide the logging of pages, events and ecommerce transactions to Google Analytics in your application. It provides a small set of tools to configure the logging and uses a view helper to convert the configation into javascript code for the Google tracker.

Requirements

Installation

Add "slm/google-analytics" to your composer.json file and update your dependencies. Enable SlmGoogleAnalytics in your application.config.php.

If you do not have a composer.json file in the root of your project, copy the contents below and put that into a file called composer.json and save it in the root of your project:

Then execute the following commands in a CLI:

Now you should have a vendor directory, including a slm/google-analytics. In your bootstrap code, make sure you include the vendor/autoload.php file to properly load the SlmGoogleAnalytics module.

Configuration

In the /config directory of this module (/vendor/slm/google-analytics) you find a file slmgoogleanalytics.global.php.dist. Copy this file to your /config/autoload/ directory of your application.

Open the configuration file and modify the values to your need. The minimum requirement is to set your tracker id in the config:

In the configuration, you can modify the following settings:

  1. Your tracking ID
  2. Disable page tracking completely (useful for your local environment)
  3. Switch to the universal.js code instead of ga.js
  4. Anonymize the IP address of visitors
  5. Enable tracking across multiple domains
  6. Enable display advertising features (DoubleClick)

Usage

After configuration, SlmGoogleAnalytics should work automatically. However, there is a PHP API available to update all above settings and perform operations for event tracking and e-commerce.

The SlmGoogleAnalytics\Analytics\Tracker is aliased to google-analytics in the Service Manager configuration. This object is used to configure the Google Analytics tracking. You can access this object inside a controller using the locator:

You can disable the tracking completely. This will result in no javascript code rendered at all:

If you want to track events and/or ecommerce transactions, but no page tracking, you can turn off the page tracking only too:

Events

To track an event, you must instantiate a SlmGoogleAnalytics\Analytics\Event and add it to the tracker:

The constructor signature of the event is

__construct($category, $action, $label = null, $value = null)

Transactions

To track a transaction, you should use the SlmGoogleAnalytics\Analytics\Ecommerce\Transaction and add one or more SlmGoogleAnalytics\Analytics\Ecommerce\Item objects.

The transaction's constructor has the following signature:

__construct($id, $total)

An item is as follows:

__construct($sku, $price, $quantity = null, $product = null, $category = null)

The Transaction and Item have accessors and mutators for every property Google is able to track (like getTax(), getShipping() and getSku()) but left out in this example for the sake of clarity.

Anonymize IP address

Some webapplications require the tracker to collect data anonymously. Google Analytics will remove the last octet of the IP address prior to its storage. This will reduce the accuracy of the geographic reporting, so understand the consequences of this feature.

To collect data anonymously, set the flag in the tracker:

Or, alternatively, you can set this flag inside the configuration:

More information about what to set in which scenario is available on the Google Help page.

Tracking multiple domains

Google Analytics offers to track statistics from multiple domain names. In order to do so, you can set the canonical domain name and optionally allow links between the different domains:

Or, alternatively, you can set these variables inside the configuration:

More information about what to set in which scenario is available on the Google Help page.

Custom variables

The tracker is capable to track custom variables. This feature differs from events, so check the Google Help for more information about custom variables.

To track a variable, instantiate a SlmGoogleAnalytics\Analytics\CustomVariable and add it to the tracker:

You can, if required, set the scope of the variable:

The scope can be SCOPE_VISITOR, SCOPE_SESSION or (the default) SCOPE_PAGE_LEVEL.

Display Advertising

To enable Google Analytics Display Advertising features simply call the appropiate method on the tracker.

Or, alternatively, you can set these variables inside the configuration:

The Google Analytics Display Advertising features include the following:

Universal Analytics or Google Analytics

You can switch to the universal.js code instead of ga.js. the default setting is to use the ga.js style. To change to the other renderer, set a variable inside the configuration:

More information about Benefits of using Universal Analytics is available on this Google Developers page.

Track client side events

You can use the javascript Google Analytics API to track events. This is done via the following API:

If you want to track clicks on outbound links or form submits, you might consider this approach:

The problem here is that browsers kill the Google Analytics request to register this event before it is completed. The browser wants to follow the new document location http://example.com and therefore abort all running asynchronous HTTP requests, including this Analytics tracking request. There is a method to track the event and thereafter follow the link, but this only works with the universal analytics.js. To help you with this, there is a utility Tracker.js.


All versions of google-analytics with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.3.
zendframework/zendframework Version ~2.2
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 slm/google-analytics contains the following files

Loading the files please wait ....