1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2016-2016 The callingallpapers.com Developer Team |
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 |
13
|
|
|
* all 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 |
21
|
|
|
* THE SOFTWARE. |
22
|
|
|
* |
23
|
|
|
* @author Andreas Heigl<[email protected]> |
24
|
|
|
* @copyright 2016-2016 The callingallpapers.com Developer Team |
25
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT-License |
26
|
|
|
* @version 0.0 |
27
|
|
|
* @since 16.01.2016 |
28
|
|
|
* @link https://github.com/joindin/callingallpapers-api |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
namespace Callingallpapers\Api\Middleware; |
32
|
|
|
|
33
|
|
|
use Psr\Http\Message\ResponseInterface; |
34
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
35
|
|
|
use TheIconic\Tracking\GoogleAnalytics\Analytics; |
36
|
|
|
|
37
|
|
|
class NotifyGoogleAnalytics |
38
|
|
|
{ |
39
|
|
|
private $analytics; |
40
|
|
|
|
41
|
|
|
public function __construct(Analytics $analytics) |
42
|
|
|
{ |
43
|
|
|
$this->analytics = $analytics; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Convert a GET-Param "type" to an Accept-Header |
48
|
|
|
* |
49
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request |
50
|
|
|
* @param \Psr\Http\Message\ResponseInterface $response PSR7 response |
51
|
|
|
* @param callable $next Next middleware |
52
|
|
|
* |
53
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
54
|
|
|
*/ |
55
|
|
|
public function __invoke( |
56
|
|
|
ServerRequestInterface $request, |
57
|
|
|
ResponseInterface $response, |
58
|
|
|
callable $next |
59
|
|
|
) { |
60
|
|
|
$response = $next($request, $response); |
61
|
|
|
|
62
|
|
|
$this->analytics |
63
|
|
|
->setEventCategory($request->getUri()->getPath()) |
64
|
|
|
->setEventAction($request->getMethod()) |
65
|
|
|
->setEventLabel('type') |
66
|
|
|
->setEventValue($response->getHeader('Content-Type')[0]) |
67
|
|
|
->setIpOverride($request->getAttribute('ip_address')) |
68
|
|
|
->setUserAgentOverride($request->getHeader('User-Agent')) |
69
|
|
|
->sendEvent(); |
70
|
|
|
|
71
|
|
|
return $response; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|