Skip to content

A composer package for the StatCounter API which supports the Laravel 5 framework.

License

Notifications You must be signed in to change notification settings

injic/laravel-statcounter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StatCounter API with support for Laravel 5

Latest Stable Version License

The package supports use with the Laravel framework (v5) providing a Stat facade for the StatCounter API. You can find the documentation for this package here.


###Setup: In order to install, add the following to your composer.json file within the require block:

{
    "require": {
        "injic/laravel-statcounter": "2.*",
    }
}

Now, run the command composer update.

Within Laravel, locate the file /config/app.php. Add the following to the providers array:

Injic\LaravelStatcounter\LaravelStatcounterServiceProvider::class,

Furthermore, add the following the aliases array:

'Stat' => Injic\LaravelStatcounter\Facades\Stat::class,

Publish the configuration

$ php artisan vendor:publish --provider="Injic\LaravelStatcounter\LaravelStatcounterServiceProvider"

Find the package's config found in /config/statcounter.php. You'll need to fill out your StatCounter username, API password, and project information. Since the config file contains further information on the individual values, here are a few things to note:

  • username is the case-sensitive login username for StatCounter
  • password referes to the API password, not the login password (see API Password)
  • default must match one of the project names under projects
  • your-project-name is the only value that isn't specified by StatCounter. It's an alias of your choosing used when calling functions which handle projects.
  • projects and security-codes must having matching keys (i.e. the project names).

###Usage:

Methods of the Stat class simplify what is needed for a StatCounter API query as described in the StatCounter API Documentation. Additionally, the Stat class was modeled off of the Laravel DB Query design, and you may expect similar methods.

You can find the documentation for this package here.


###Examples:

// Retrieve an array of browser objects (http://api.statcounter.com/docs/v3#browsers)
$stats = Stat::browsers()->get();

// Retrieve an array of summary objects (http://api.statcounter.com/docs/v3#summary-daily)
$now = \Carbon\Carbon::now(); // http://carbon.nesbot.com/
$stats = Stat::summary()->setRange(Granularity::DAILY, $now->subWeek(), $now)->get();

// Paginate the recent visitor objects (http://api.statcounter.com/docs/v3#visitors)
// https://laravel.com/docs/5.2/pagination
$stats = Stat::recentVisitors()->paginate(20);

// Add new project to StatCounter with the project name, project url, and project timezone
$project Stat::addProject('project-name','www.example.com','America/Chicago');
<html>
<body>
<!-- Prints the StatCounter tracker using Laravel Templates -->
{!! Stat::tracker() !!}
</body>
</html>

About

A composer package for the StatCounter API which supports the Laravel 5 framework.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages