PHPackages                             tag-planet/universal-analytics - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tag-planet/universal-analytics

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

tag-planet/universal-analytics
==============================

Provides an easy way to include Universal Analytics code with your Laravel 4 application

1.0.1(12y ago)43202MITPHPPHP &gt;=5.4.0

Since Dec 2Pushed 12y ago2 watchersCompare

[ Source](https://github.com/TagPlanet/universal-analytics)[ Packagist](https://packagist.org/packages/tag-planet/universal-analytics)[ RSS](/packages/tag-planet-universal-analytics/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

Universal Analytics for Laravel 4
=================================

[](#universal-analytics-for-laravel-4)

#### Add Universal Analytics to your Laravel 4 application easily.

[](#add-universal-analytics-to-your-laravel-4-application-easily)

[Universal Analytics](https://support.google.com/analytics/answer/2790010?hl=en) is the new code base for [Google Analytics](https://www.google.com/analytics/). This package allows you to easily add it to your Laravel 4 application.

[![Build Status](https://camo.githubusercontent.com/5f5d089a61b9227769a88d0a7785e18ad578f75810244db1725eee069b939a7e/68747470733a2f2f6170692e7472617669732d63692e6f72672f546167506c616e65742f756e6976657273616c2d616e616c79746963732e706e67)](https://travis-ci.org/TagPlanet/universal-analytics)[![ProjectStatus](https://camo.githubusercontent.com/425b3ebcd7bb21a6c7e02525988a7a85f6564ae47c00dcbf33a3e570a5e6ab61/687474703a2f2f7374696c6c6d61696e7461696e65642e636f6d2f546167506c616e65742f756e6976657273616c2d616e616c79746963732e706e67)](http://stillmaintained.com/TagPlanet/universal-analytics)

Table of Contents
-----------------

[](#table-of-contents)

1. [Installation](#installation)
2. [Usage](#usage)1. [Overview](#overview)1. [Creating new instances](#creating-new-instances)1. [Getting an existing instance](#getting-an-existing-instance)1. [Calling methods](#calling-methods)1. [Rendering](#rendering)
3. [Configuration](#configuration)1. [Debug mode](#debug-mode)1. [Auto pageviews](#auto-pageviews)1. [Accounts](#accounts)
4. [Release notes](#release-notes)
5. [License](#license)
6. [Finding help](#finding-help)

Installation
------------

[](#installation)

Installation is simple thanks to [composer](http://getcomposer.org/). First, add the following `require` key to your `composer.json` file:

```
"tag-planet/universal-analytics": "dev-master"

```

And run the Composer update command:

```
$ composer update

```

Then, in your `config/app.php` file add `'TagPlanet\UniversalAnalytics\UniversalAnalyticsServiceProvider'` to the end of the `$providers` array:

```
'providers' => array(
    'Illuminate\Foundation\Providers\ArtisanServiceProvider',
    'Illuminate\Auth\AuthServiceProvider',
    ...
    'TagPlanet\UniversalAnalytics\UniversalAnalyticsServiceProvider',
),
```

Also in your `config/app.php` file add `'UniversalAnalytics' => 'TagPlanet\UniversalAnalytics\UniversalAnalyticsFacade'`to the end of the `$aliases` array:

```
'aliases' => array(
    'App'        => 'Illuminate\Support\Facades\App',
    'Artisan'    => 'Illuminate\Support\Facades\Artisan',
    ...
    'UniversalAnalytics' => 'TagPlanet\UniversalAnalytics\UniversalAnalyticsFacade'
),
```

Next, you'll want to publish the config files:

```
$ php artisan config:publish tag-planet/universal-analytics

```

Now you'll be able to edit the configuration options within `app/config/packages/tag-planet/universal-analytics/settings.php`

Usage
-----

[](#usage)

#### Overview

[](#overview)

This package closely replicates the JavaScript code syntax to help developers easily transition to and from using this package. Below is an example of the same call, one in JavaScript and the other in PHP:

```
// JavaScript:
ga('create', 'UA-123456-1', {'name': 'foo'});

// PHP
UniversalAnalytics::ga('create', 'UA-123456-1', ['name'=>'foo']);

```

You can use any of the `ga` calls, just like you would with the JavaScript version. This will output the same code.

```
UniversalAnalytics::ga('create', 'UA-123456-1', ['name'=>'foo', 'domainName' => 'tagpla.net']);
```

Will output as the following in JS:

```
ga("create", "UA-123456-1", {
    "name": "foo",
    "domainName": "tagpla.net"
});
```

#### Creating new instances

[](#creating-new-instances)

While the option exists to [auto create trackers](#accounts) via the configuration file, you can also create new instances on your own. Again, all you'll need to do is call `UniversalAnalytics::ga( ... )` with the same arguments as you would pass in the JavaScript version:

```
// Setup a new tracker with "foo" as its name:
$fooTracker = UniversalAnalytics::ga('create', 'UA-123456-1', ['name'=>'foo', 'domainName' => 'tagpla.net']);
```

It is highly recommended to pass a name to the tracker, but one will automatically be generated for you in the event it is missing. In this case, the name is `foo`, as seen in the options array. If a name hasn't been passed in the naming schema is `tX` where X is the count of previous instances. E.g.:

```
// Name would be "foo":
UniversalAnalytics::ga('create', 'UA-123456-1', ['name'=>'foo']);

// Name would be "t1":
UniversalAnalytics::ga('create', 'UA-123456-2');

// Name would be "bar":
UniversalAnalytics::ga('create', 'UA-123456-3', ['name'=>'bar', 'domainName' => 'tagpla.net']);

// Name would be "t3":
UniversalAnalytics::ga('create', 'UA-123456-4', ['domainName' => 'tagpla.net']);
```

#### Getting an existing instance

[](#getting-an-existing-instance)

Now that you've created a tracker instance, you may need to grab it to call additional methods. If you created the tracker instance via the configuration, you'll use the friendly name you used as the key (*See: [Accounts](#accounts)*):

```
// Grab the "foo" instance
$tracker = UniversalAnalytics::get('foo');
```

#### Calling methods

[](#calling-methods)

It is likely that you'll want to add custom variables (dimensions / metrics) or track certain events. Since the argument format is the same as the JavaScript version, explaining all of the options is out of scope for this document. You can read up on the format over at [Google's documentation](https://developers.google.com/analytics/devguides/collection/analyticsjs/).

You can push to a single instance once you've grabbed it (*see: [Getting an existing instance](#getting-an-existing-instance)*):

```
// Grab the "foo" instance
$fooTracker = UniversalAnalytics::get('foo');

// Call a pageview event to the "foo" instance
$fooTracker->ga('send', 'pageview');
```

A more complex example, using ecommerce tracking:

```
// Grab the "foo" instance
$fooTracker = UniversalAnalytics::get('foo');

// Require the ecommerce JS file:
$fooTracker->ga('require', 'ecommerce', 'ecommerce.js');

// Setup a transaction:
$fooTracker->ga('ecommerce:addTransaction', [
    'id'          => $order->id
    'addiliation' => $store->name,
    'revenue'     => $order->total,
    'shipping'    => $order->shipping->cost,
    'tax'         => $order->tax,
]);
```

In addition to pushing to a single instance, you can also push to all existing instances in one call:

```
// Have a pageview across all instances
UniversalAnalytics::ga('send', 'pageview');
```

#### Rendering

[](#rendering)

Now that you've created an instance and pushed data to it, you're going to want to render the JavaScript output at some point.

##### Render options

[](#render-options)

There are 3 optional boolean arguments you can pass in to the `render` method.

```
function render($renderCodeBlock = true, $renderJavaScriptTags = true, $clearData = true);
```

`$renderCodeBlock`, will render the default Universal Analytics code block when set to `true`. By default this is set to `true`. If you've already output the code block on the page, set it to `false`.

```
// A sample of what it'll render when set to true:
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
```

> Remember, you only need to have the code block rendered once per page.

`$renderJavaScriptTags`, will render the ` ... ` tags around the code. By default this is set to `true`. If you're appending the output to an existing JavaScript tag, set it to `false`.

`$clearData`, will clear all previous calls once the render is complete. If you have multiple renders on a page for any reason, you should set this to `true`. Otherwise you'll get duplicate calls.

All of these arguments can be used when rendering all instances or just a single instance.

##### Render all instances

[](#render-all-instances)

In most cases you'll want to render all of the instances at once. To do this, place the following code just before the `` of your main view layout:

```
// For blade templates:
{{ UniversalAnalytics::render() }}

// For raw PHP templates:
echo UniversalAnalytics::render();
```

> If you prefer, you can also use a [View composer](http://laravel.com/docs/responses#view-composers).

##### Rendering single instances

[](#rendering-single-instances)

You can also render single instances if you need to:

```
// Grab the "foo" instance
$fooTracker = UniversalAnalytics::get('foo');

// render it!
echo $fooTracker->render();
```

Configuration
-------------

[](#configuration)

Once you've published your configuration file, you can edit it at `app/config/packages/tag-planet/universal-analytics/settings.php`. If you'd like to use configuration files on an enviroment-based level, you can do so via [these instructions](http://laravel.com/docs/configuration#environment-configuration).

#### Debug mode

[](#debug-mode)

Debug mode uses a different JS file that outputs information about what is sent to Universal Analytics via the browser console. This mode can be enabled by changing `debug` to `true`, or disabled by changing it to `false`. By default this is set to `true`.

```
'debug' => false,
```

> This should be set to `false` on production domains.

#### Auto pageviews

[](#auto-pageviews)

When auto pageviews are enabled, any time the `render` call has occured, a [pageview event](https://developers.google.com/analytics/devguides/collection/analyticsjs/pages#implementation)will automatically be appended. If there is not a need to pass in customized page locations or page titles, then it is recommended to leave this enabled. While the configuration setting is for a global basis, this setting can be overwritten on a per-instance level.

```
'autoPageview' => true,
```

#### Accounts

[](#accounts)

While you can manually create new tracker instances (as discussed earlier in this guide) you can also have them auto-created. There are 2 different configuration formats, depending on your needs. Both require a friendly name and an account ID. The friendly name should be a **unique** alpha-numeric name that is used to identify each tracker. You can use something as simple as "default" to more complex names such as "tagplanetInstall". You can read more about tracker names over at
[Google's documentation](https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#multipletrackers). Account IDs are also required and are provided to you when you create a new account or property within Google Analytics. If you're not sure on what this is, please take a look at [Google's help file](https://support.google.com/analytics/answer/1032385?hl=en) to find it.

##### Basic format

[](#basic-format)

For those that don't need extra configuration options you can use the simplified format. The following example uses the friendly name "trackerName" and an account ID of "UA-123456-1":

```
'accounts' => array(
    'trackerName' => 'UA-123456-1',
),
```

##### Advanced format

[](#advanced-format)

For those that do need extra configuration when you do a create call (e.g. setting the cookie domain or any of the [create-only fields](https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#create)), you'll need to use the more advanced format. The following examples uses a friendly name of "foobar" and an account of "UA-654321-1":

```
'accounts' => array(
    'foobar' => array(
        'account' => 'UA-654321-1',
        'options' => array(
            'domainName' => 'foobar.com',
        ),
    ),
),
```

Release notes
-------------

[](#release-notes)

#### Version 1.0.0

[](#version-100)

Initial Version

License
-------

[](#license)

Tag Planet's Universal Analytics for Laravel 4 is free software distributed under the terms of the MIT license.

Finding help
------------

[](#finding-help)

Should you have any questions, bug reports, or feedback please utilize our [issue tracker](https://github.com/TagPlanet/universal-analytics/issues).

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~54 days

Total

2

Last Release

4493d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/950141?v=4)[Philip Lawrence](/maintainers/MisterPhilip)[@MisterPhilip](https://github.com/MisterPhilip)

---

Top Contributors

[![MisterPhilip](https://avatars.githubusercontent.com/u/950141?v=4)](https://github.com/MisterPhilip "MisterPhilip (13 commits)")

### Embed Badge

![Health badge](/badges/tag-planet-universal-analytics/health.svg)

```
[![Health](https://phpackages.com/badges/tag-planet-universal-analytics/health.svg)](https://phpackages.com/packages/tag-planet-universal-analytics)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
