Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSchmidhuber committed Dec 19, 2019
0 parents commit 8de2735
Show file tree
Hide file tree
Showing 11 changed files with 700 additions and 0 deletions.
1 change: 1 addition & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
preset: laravel
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog

All notable changes to `MatomoTracker` will be documented in this file.

## Version 0.1

### Added
- Everything
43 changes: 43 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "alfrasc/laravel-matomo-tracker",
"description": ":description",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Alexander Schmidhuber",
"email": "[email protected]",
"homepage": "https://schmidhuber.co.at"
}
],
"homepage": "https://github.com/alfrasc/matomotracker",
"keywords": ["Laravel", "Matomo PHP Tracker"],
"require": {
"piwik/piwik-php-tracker": "^1.5"
},
"require-dev": {
"phpunit/phpunit": "~7.0",
"mockery/mockery": "^1.1",
"orchestra/testbench": "~3.0",
"sempro/phpunit-pretty-print": "^1.0"
},
"autoload": {
"psr-4": {
"Alfrasc\\MatomoTracker\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Alfrasc\\MatomoTracker\\Tests\\": "tests"
}
},
"extra": {
"laravel": {
"providers": [
"Alfrasc\\MatomoTracker\\MatomoTrackerServiceProvider"
],
"aliases": {
"MatomoTracker": "Alfrasc\\MatomoTracker\\Facades\\MatomoTracker"
}
}
}
}
24 changes: 24 additions & 0 deletions config/matomotracker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

return [

/**
* The URL of your Matomo install
*/
'url' => env('MATOMO_URL', ''),

/**
* The id of the site that should be tracked
*/
'idSite' => env('MATOMO_SITE_ID', 1),

/**
* The auth token of your user
*/
'tokenAuth' => env('MATOMO_AUTH_TOKEN', ''),

/**
* For queuing the tracking you can use custom queue names. Use 'default' if you want to run the queued items within the standard queue.
*/
'queue' => env('MATOMO_QUEUE', 'matomotracker')
];
24 changes: 24 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Contributing

Contributions are welcome and will be fully credited.

Contributions are accepted via Pull Requests on [Github](https://github.com/alfrasc/laravel-matomo-tracker).

# Things you could do
If you want to contribute but do not know where to start, this list provides some starting points.
- Write a comprehensive ReadMe

## Pull Requests

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

- **Document any change in behaviour** - Make sure the `readme.md` and any other relevant documentation are kept up-to-date.

- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.


**Happy coding**!
13 changes: 13 additions & 0 deletions license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# The license

Copyright (c) 2019 Alexander Schmidhuber <[email protected]>

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 changes: 22 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Package">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src/</directory>
</whitelist>
</filter>
</phpunit>
121 changes: 121 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# MatomoTracker

[![Latest Version on Packagist][ico-version]][link-packagist]
[![Total Downloads][ico-downloads]][link-downloads]
[![Build Status][ico-travis]][link-travis]
[![StyleCI][ico-styleci]][link-styleci]

## About

The `alfrasc\laravel-matomo-tracker` Laravel package is a wrapper for the `piwik\piwik-php-tracker`. The Piwik php tracker allows serverside tracking.

## Features

* MatomoTracker Facade
* Queued tracking requests in Laravel queue

Feel free to suggest new features.

## Installation

Via Composer

Require the `alfrasc\laravel-matomo-tracker` package in your `composer.json` and update your dependencies:
``` bash
$ composer require alfrasc/laravel-matomo-tracker
```

Publish the config file (optional)

Run `php artisan vendor:publish` to publish the config file if needed.
``` bash
$ php artisan vendor:publish
```

Update your `.env`

Add these variables to your `.env` file and configure it to fit your environment.
``` bash
[...]
MATOMO_URL="https://your.matomo-install.com"
MATOMO_SITE_ID=1
MATOMO_AUTH_TOKEN="00112233445566778899aabbccddeeff"
MATOMO_QUEUE="matomotracker"
[...]
```

That's it!

## Usage

You can use the facade to track.

``` bash
MatomoTracker::doTrackPageView('Page Title')
```

### Basic functionality

Please see the https://developer.matomo.org/api-reference/PHP-Piwik-Tracker page for basic method documentation.

Additionally there are some Methods to simplyfy the usage:
``` bash
// instead of using
MatomoTracker::doTrackAction($actionUrl, 'download') // or
MatomoTracker::doTrackAction($actionUrl, 'link')

// you can use this
MatomoTracker::doTrackDownload($actionUrl);
MatomoTracker::doTrackOutlink($actionUrl);
```

### Queues

For queuing you can use these functions.
``` bash
MatomoTracker::queuePageView(string $documentTitle)
MatomoTracker::queueEvent(string $category, string $action, $name = false, $value = false)
MatomoTracker::queueContentImpression(string $contentName, string $contentPiece = 'Unknown', $contentTarget = false)
MatomoTracker::queueContentInteraction(string $interaction, string $contentName, string $contentPiece = 'Unknown', $contentTarget = false)
MatomoTracker::queueSiteSearch(string $keyword, string $category = '', $countResults = false)
MatomoTracker::queueGoal($idGoal, $revencue = 0.0)
MatomoTracker::queueDownload(string $actionUrl)
MatomoTracker::queueOutlink(string $actionUrl)
MatomoTracker::queueEcommerceCartUpdate(float $grandTotal)
MatomoTracker::queueEcommerceOrder(float $orderId, float $grandTotal, float $subTotal = 0.0, float $tax = 0.0, float $shipping = 0.0, float $discount = 0.0)
MatomoTracker::queueBulkTrack()
```

For setting up queues, find the documentation on https://laravel.com/docs/6.x/queues.

## Change log

Please see the [changelog](changelog.md) for more information on what has changed recently.


## Contributing

Please see [contributing.md](contributing.md) for details and a todolist.

## Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

## Credits

- [Alexander Schmidhuber][link-author]
- [All Contributors][link-contributors]

## License

BSD-3-Clause. Please see the [license file](license.md) for more information.

[ico-version]: https://img.shields.io/packagist/v/alfrasc/laravel-matomo-tracker.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/alfrasc/laravel-matomo-tracker.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/alfrasc/laravel-matomo-tracker/master.svg?style=flat-square
[ico-styleci]: https://styleci.io/repos/12345678/shield

[link-packagist]: https://packagist.org/packages/alfrasc/laravel-matomo-tracker
[link-downloads]: https://packagist.org/packages/alfrasc/laravel-matomo-tracker
[link-author]: https://github.com/alfrasc
[link-contributors]: ../../contributors
18 changes: 18 additions & 0 deletions src/Facades/MatomoTracker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Alfrasc\MatomoTracker\Facades;

use Illuminate\Support\Facades\Facade;

class MatomoTracker extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'matomotracker';
}
}
Loading

0 comments on commit 8de2735

Please sign in to comment.