Skip to content
This repository was archived by the owner on Feb 17, 2022. It is now read-only.

Commit 088fc48

Browse files
committed
first commit
0 parents  commit 088fc48

File tree

15 files changed

+802
-0
lines changed

15 files changed

+802
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor
2+
composer.phar
3+
composer.lock
4+
.DS_Store

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
8+
before_script:
9+
- curl -s http://getcomposer.org/installer | php
10+
- php composer.phar install --dev
11+
12+
script: phpunit

README.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Analytics tracking package for Laravel 4.x
2+
3+
## Installation
4+
5+
Add to your composer.json following lines
6+
7+
"repositories": [
8+
{
9+
"type": "vcs",
10+
"url": "https://github.com/ipunkt/laravel-analytics"
11+
}
12+
],
13+
"require": {
14+
"ipunkt/laravel-analytics": "dev-master"
15+
}
16+
17+
Run `php artisan config:publish ipunkt/laravel-analytics`
18+
19+
Then edit `analytics.php` in `app/config/packages/ipunkt/laravel-analytics` to your needs.
20+
21+
Add `'Ipunkt\LaravelAnalytics\AnalyticsServiceProvider',` to `providers` in `app/config/app.php`.
22+
23+
Add `'Analytics' => 'Ipunkt\LaravelAnalytics\AnalyticsFacade',` to `aliases` in `app/config/app.php`.
24+
25+
26+
## Configuration
27+
28+
provider - Provider to use, possible Providers are: GoogleAnalytics, NoAnalytics
29+
30+
### Google Analytics
31+
32+
tracking_id - Tracking ID
33+
34+
tracking_domain - Tracking domain, unset or set to "auto" for automatic fallback
35+
36+
anonymize_ip - (true|false) anonymize users ip
37+
38+
auto_track - (true|false) auto tracking current pageview
39+
40+
## Usage
41+
42+
In controller action (or anywhere else) use following statement to track an event or page view:
43+
44+
// tracking the current page view
45+
Analytics::trackPage(); // only necessary if `auto_track` is false or Analytics::disableAutoTracking() was called before
46+
47+
// tracking an event
48+
Analytics::trackEvent('category', 'action');
49+
50+
// tracking a custom line
51+
Analytics::trackCustom("ga('send', ......"); // this line will be added within the tracking script
52+
53+
In your view or layout template (e.g. a blade template) use the following statement:
54+
55+
{{ Analytics::render() }}
56+
57+
For Google Analytics you should place the statement right behind the `body` tag
58+
59+
<body>{{ Analytics::render() }}
60+
61+
## How to use
62+
63+
The `GoogleAnalytics` Provider automatically controls the local environment behaviour for testing purposes.
64+
See https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#localhost for details.
65+
66+
There is a builtin provider called `NoAnalytics`. This is for testing environments and tracks nothing. So you do
67+
not have to rewrite your code, simple select this `provider` in `analytics` configuration for your special environment
68+
configurations.
69+
70+
71+
## API Documentation
72+
73+
For the correct usage methods look at the `Ipunkt\LaravelAnalytics\Contracts\AnalyticsProviderInterface.php`
74+
75+
### Analytics::render()
76+
77+
For rendering the correct javascript code.
78+
79+
/**
80+
* returns the javascript code for embedding the analytics stuff
81+
*
82+
* @return string
83+
*/
84+
public function render();
85+
86+
87+
### Analytics::trackPage()
88+
89+
For tracking a page view.
90+
91+
/**
92+
* track an page view
93+
*
94+
* @param null|string $page
95+
* @param null|string $title
96+
* @param null|string $hittype
97+
* @return void
98+
*/
99+
public function trackPage($page, $title, $hittype);
100+
101+
102+
### Analytics::trackEvent()
103+
104+
For tracking an event
105+
106+
/**
107+
* track an event
108+
*
109+
* @param string $category
110+
* @param string $action
111+
* @param null|string $label
112+
* @param null|int $value
113+
* @return void
114+
*/
115+
public function trackEvent($category, $action, $label, $value);
116+
117+
118+
### Analytics::trackCustom()
119+
120+
For tracking a custom script line within the embedded analytics code.
121+
122+
/**
123+
* track any custom code
124+
*
125+
* @param string $customCode
126+
* @return void
127+
*/
128+
public function trackCustom($customCode);
129+
130+
131+
### Analytics::enableAutoTracking()
132+
133+
Enabling the auto tracking, overriding the configuration setting `auto_track`.
134+
135+
/**
136+
* enable auto tracking
137+
*
138+
* @return void
139+
*/
140+
public function enableAutoTracking();
141+
142+
143+
### Analytics::disableAutoTracking()
144+
145+
Disabling the auto tracking, overriding the configuration setting `auto_track`.
146+
147+
/**
148+
* disable auto tracking
149+
*
150+
* @return void
151+
*/
152+
public function disableAutoTracking();
153+

composer.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "ipunkt/laravel-analytics",
3+
"version": "1.0.0",
4+
"type": "library",
5+
"description": "Analytics tracking for laravel 4.x",
6+
"keywords": ["analytics", "google analytics", "laravel", "statistics", "javascript", "php"],
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "ipunkt",
11+
"email": "info@ipunkt.biz"
12+
}
13+
],
14+
"require": {
15+
"php": ">=5.3.0",
16+
"illuminate/support": "~4.0"
17+
},
18+
"autoload": {
19+
"psr-0": {
20+
"Ipunkt\\LaravelAnalytics\\": "src/"
21+
}
22+
},
23+
"minimum-stability": "stable"
24+
}

phpunit.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
>
13+
<testsuites>
14+
<testsuite name="Package Test Suite">
15+
<directory suffix=".php">./tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* mitarbeiterbereich2
4+
*
5+
* @author rok
6+
* @since 07.03.14
7+
*/
8+
9+
namespace Ipunkt\LaravelAnalytics;
10+
11+
12+
use Illuminate\Support\Facades\Facade;
13+
14+
class AnalyticsFacade extends Facade {
15+
16+
/**
17+
* facade accessor
18+
*
19+
* @return string
20+
*/
21+
protected static function getFacadeAccessor()
22+
{
23+
return 'analytics';
24+
}
25+
26+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php namespace Ipunkt\LaravelAnalytics;
2+
3+
use Config;
4+
use Illuminate\Support\ServiceProvider;
5+
6+
class AnalyticsServiceProvider extends ServiceProvider {
7+
8+
/**
9+
* Indicates if loading of the provider is deferred.
10+
*
11+
* @var bool
12+
*/
13+
protected $defer = false;
14+
15+
/**
16+
* Bootstrap the application events.
17+
*
18+
* @return void
19+
*/
20+
public function boot()
21+
{
22+
$this->package('ipunkt/laravel-analytics');
23+
}
24+
25+
/**
26+
* Register the service provider.
27+
*
28+
* @return void
29+
*/
30+
public function register()
31+
{
32+
$this->app->bind('analytics', function () {
33+
34+
// get analytics provider name
35+
$provider = Config::get('ipunkt/laravel-analytics::analytics.provider');
36+
37+
// make it a class
38+
$providerClass = 'Ipunkt\LaravelAnalytics\Providers\\' . $provider;
39+
40+
// getting the config
41+
$providerConfig = [];
42+
if (Config::has('analytics.configurations.' . $provider))
43+
{
44+
$providerConfig = Config::get('analytics.configurations.' . $provider);
45+
}
46+
47+
// return an instance
48+
return new $providerClass($providerConfig);
49+
});
50+
}
51+
52+
/**
53+
* Get the services provided by the provider.
54+
*
55+
* @return array
56+
*/
57+
public function provides()
58+
{
59+
return array();
60+
}
61+
62+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* mitarbeiterbereich2
4+
*
5+
* @author rok
6+
* @since 07.03.14
7+
*/
8+
9+
namespace Ipunkt\LaravelAnalytics\Contracts;
10+
11+
12+
interface AnalyticsProviderInterface {
13+
14+
/**
15+
* returns the javascript code for embedding the analytics stuff
16+
*
17+
* @return string
18+
*/
19+
public function render();
20+
21+
/**
22+
* track an page view
23+
*
24+
* @param null|string $page
25+
* @param null|string $title
26+
* @param null|string $hittype
27+
* @return void
28+
*/
29+
public function trackPage($page, $title, $hittype);
30+
31+
/**
32+
* track an event
33+
*
34+
* @param string $category
35+
* @param string $action
36+
* @param null|string $label
37+
* @param null|int $value
38+
* @return void
39+
*/
40+
public function trackEvent($category, $action, $label, $value);
41+
42+
/**
43+
* track any custom code
44+
*
45+
* @param string $customCode
46+
* @return void
47+
*/
48+
public function trackCustom($customCode);
49+
50+
/**
51+
* enable auto tracking
52+
*
53+
* @return void
54+
*/
55+
public function enableAutoTracking();
56+
57+
/**
58+
* disable auto tracking
59+
*
60+
* @return void
61+
*/
62+
public function disableAutoTracking();
63+
}

0 commit comments

Comments
 (0)