Skip to content

Commit 4803860

Browse files
authored
Add files via upload
0 parents  commit 4803860

23 files changed

+2048
-0
lines changed

Gulpfile.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var gulp = require('gulp');
2+
var phpunit = require('gulp-phpunit');
3+
var run = require('gulp-run');
4+
var notify = require('gulp-notify');
5+
6+
gulp.task('test', function() {
7+
gulp.src('phpunit.xml')
8+
.pipe(run('clear'))
9+
.pipe(phpunit('', { notify: true }))
10+
.on('error', notify.onError({
11+
title: 'Red!',
12+
message: 'Your tests failed...'
13+
}))
14+
.pipe(notify(
15+
{
16+
title: 'Green!',
17+
message: 'Your tests succeeded!'
18+
}
19+
));
20+
});
21+
22+
gulp.task('watch', function() {
23+
gulp.watch(['tests/**/*.php'], ['test']);
24+
});
25+
26+
gulp.task('default', ['test', 'watch']);

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 kenarkose
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Tracker
2+
Simple site visit/statistics tracker for Laravel 5.
3+
4+
---
5+
6+
Tracker provides a simple way to track your site visits and their statistics.
7+
8+
## Features
9+
- Compatible with Laravel 5
10+
- Middleware for automatically recording the site view
11+
- Associate site views to Eloquent models to track their views
12+
- Persists unique views based on URL, method, and IP address
13+
- Helper method, Facade, and trait for easing access to services
14+
- Handy 'Cruncher' for number crunching needs
15+
- Flushing and selecting site views with given time spans
16+
- A [phpunit](http://www.phpunit.de) test suite for easy development
17+
18+
## Installation
19+
Installing Tracker is simple.
20+
21+
1. Pull this package in through [Composer](https://getcomposer.org).
22+
23+
```js
24+
{
25+
"require": {
26+
"arrtrust/tracker": "~1.6"
27+
}
28+
}
29+
```
30+
31+
2. In order to register Tracker Service Provider add `'Arrtrust\Tracker\TrackerServiceProvider'` to the end of `providers` array in your `config/app.php` file.
32+
```php
33+
'providers' => array(
34+
35+
'Illuminate\Foundation\Providers\ArtisanServiceProvider',
36+
'Illuminate\Auth\AuthServiceProvider',
37+
...
38+
'Arrtrust\Tracker\TrackerServiceProvider',
39+
40+
),
41+
```
42+
43+
3. You may configure the default behaviour of Tracker by publishing and modifying the configuration file. To do so, use the following command.
44+
```bash
45+
php artisan vendor:publish
46+
```
47+
Than, you will find the configuration file on the `config/tracker.php` path. Information about the options can be found in the comments of this file. All of the options in the config file are optional, and falls back to default if not specified; remove an option if you would like to use the default.
48+
49+
This will also publish the migration file for the default `SiteView` model. Do not forget to migrate your database before using Tracker.
50+
51+
4. In order to register the Facade add the following line to the end of `aliases` array in your `config/app.php` file.
52+
```php
53+
'aliases' => array(
54+
55+
'App' => 'Illuminate\Support\Facades\App',
56+
'Artisan' => 'Illuminate\Support\Facades\Artisan',
57+
...
58+
'Tracker' => 'Arrtrust\Tracker\TrackerFacade'
59+
60+
),
61+
```
62+
63+
5. You may now access Tracker either by the Facade or the helper function.
64+
```php
65+
tracker()->getCurrent();
66+
Tracker::saveCurrent();
67+
68+
tracker()->isViewUnique();
69+
tracker()->isViewValid();
70+
71+
tracker()->addTrackable($post);
72+
73+
Tracker::flushAll();
74+
Tracker::flushOlderThan(Carbon::now());
75+
Tracker::flushOlderThenOrBetween(Carbon::now(), Carbon::now()->subYear());
76+
```
77+
78+
6. It is important to record views by using the supplied middleware to record correct app runtime and memory information. To do so register the middleware in `app\Http\Kernel`.
79+
```php
80+
protected $routeMiddleware = [
81+
'auth' => \App\Http\Middleware\Authenticate::class,
82+
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
83+
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
84+
'guard' => \App\Http\Middleware\Guard::class,
85+
'track' => \Arrtrust\Tracker\TrackerMiddleware::class
86+
];
87+
```
88+
It is better to register this middleware as a routeMiddleware instead of a global middleware and use it in routes or route groups definitions as it may not be necessary to persist all site view. This will persist and attach any Trackable that is added to stack to site views automatically when the request has been handled by Laravel.
89+
90+
7. To attach views to any model or class, you should implement the `Arrtrust\Tracker\TrackableInterface` interface. Tracker provides `Arrtrust\Tracker\Trackable` trait to be used by Eloquent models.
91+
```php
92+
93+
use Illuminate\Database\Eloquent\Model as Eloquent;
94+
use Arrtrust\Tracker\Trackable;
95+
use Arrtrust\Tracker\TrackableInterface;
96+
97+
class Node extends Eloquent implements TrackableInterface {
98+
99+
use Trackable;
100+
101+
}
102+
```
103+
104+
The `Trackable` trait uses Eloquent's `belongsToMany` relationship which utilizes pivot tables. Here is a sample migration for the pivot table:
105+
```php
106+
<?php
107+
108+
use Illuminate\Database\Schema\Blueprint;
109+
use Illuminate\Database\Migrations\Migration;
110+
111+
class CreateNodeSiteViewPivotTable extends Migration {
112+
113+
/**
114+
* Run the migrations.
115+
*
116+
* @return void
117+
*/
118+
public function up()
119+
{
120+
Schema::create('node_site_view', function (Blueprint $table)
121+
{
122+
$table->integer('node_id')->unsigned();
123+
$table->integer('site_view_id')->unsigned();
124+
125+
$table->foreign('node_id')
126+
->references('id')
127+
->on('nodes')
128+
->onDelete('cascade');
129+
130+
$table->foreign('site_view_id')
131+
->references('id')
132+
->on('site_views')
133+
->onDelete('cascade');
134+
135+
$table->primary(['node_id', 'site_view_id']);
136+
});
137+
}
138+
139+
/**
140+
* Reverse the migrations.
141+
*
142+
* @return void
143+
*/
144+
public function down()
145+
{
146+
Schema::drop('node_site_view');
147+
}
148+
}
149+
150+
```
151+
152+
8. Check the `Arrtrust\Tracker\Cruncher` class and test for statistics number crunching. It is equipped with a number of methods for different types of statistics (mostly counts) in different time spans.
153+
154+
Please check the tests and source code for further documentation, as the source code of Tracker is well tested and documented.
155+
156+
## License
157+
Tracker is released under [MIT License](https://github.com/arrtrust/Tracker/blob/master/LICENSE).

composer.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "arrtrust/tracker",
3+
"description": "Simple site visit/statistics tracker for Laravel 5",
4+
"license": "MIT",
5+
"keywords": [
6+
"tracker",
7+
"analytics",
8+
"visitor",
9+
"statistics",
10+
"laravel",
11+
"laravel5"
12+
],
13+
"version": "1.6.3",
14+
"require": {
15+
"php": ">=5.4.0"
16+
},
17+
"require-dev": {
18+
"orchestra/testbench": "~3.0",
19+
"phpunit/phpunit": "~4.0"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"Arrtrust\\Tracker\\": "src/"
24+
},
25+
"files": [
26+
"src/helpers.php"
27+
]
28+
},
29+
"autoload-dev": {
30+
"classmap": [
31+
"tests"
32+
]
33+
},
34+
"suggest": {
35+
"laravel/framework": "This package requires Laravel 5."
36+
}
37+
}

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"devDependencies": {
3+
"gulp": "^3.8.11",
4+
"gulp-notify": "^2.2.0",
5+
"gulp-phpunit": "^0.8.1",
6+
"gulp-run": "^1.6.6"
7+
}
8+
}

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+
<testsuites>
13+
<testsuite name="Package Test Suite">
14+
<directory suffix=".php">./tests/</directory>
15+
<exclude>./tests/TestBase.php</exclude>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>

0 commit comments

Comments
 (0)