<commit_before># Universal Analytics for Laravel 4
#### 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://api.travis-ci.org/TagPlanet/universal-analytics.png)](https://travis-ci.org/TagPlanet/universal-analytics)
[![ProjectStatus](http://stillmaintained.com/TagPlanet/universal-analytics.png)](http://stillmaintained.com/TagPlanet/universal-analytics)

## Table of Contents
  1. [Installation](#installation)
  1. [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)
  1. [Configuration](#configuration)
    1. [Debug mode](#debug-mode)
    1. [Auto pageviews](#auto-pageviews)
    1. [Accounts](#accounts)
  1. [Release notes](#release-notes)
  1. [License](#license)
  1. [Finding help](#finding-help)

## 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:

```php
'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:

```php
'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

#### 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. 

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

Will output as the following in JS:

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

#### 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:

```php
// 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.:

```php
// 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
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)_):

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


#### 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)_):

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

// Call a pageview event to the "foo" instance<commit_msg>Fix UniversalAnalytics:ga typo<commit_after># Universal Analytics for Laravel 4
#### 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://api.travis-ci.org/TagPlanet/universal-analytics.png)](https://travis-ci.org/TagPlanet/universal-analytics)
[![ProjectStatus](http://stillmaintained.com/TagPlanet/universal-analytics.png)](http://stillmaintained.com/TagPlanet/universal-analytics)

## Table of Contents
  1. [Installation](#installation)
  1. [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)
  1. [Configuration](#configuration)
    1. [Debug mode](#debug-mode)
    1. [Auto pageviews](#auto-pageviews)
    1. [Accounts](#accounts)
  1. [Release notes](#release-notes)
  1. [License](#license)
  1. [Finding help](#finding-help)

## 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:

```php
'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:

```php
'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

#### 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. 

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

Will output as the following in JS:

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

#### 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:

```php
// 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.:

```php
// 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
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)_):

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


#### 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)_):

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

// Call a pageview event to the "foo" instance
{'fraction_non_alphanumeric': 0.14301572617946345, 'fraction_numerical': 0.016466234967622572, 'mean_word_length': 4.753592336349122, 'pattern_counts': {'":': 14, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5334344', 'n_tokens_mistral': 3482, 'n_tokens_neox': 3201, 'n_words': 1095}