File: MultiDeviceGoalConversions.php

package info (click to toggle)
matomo 5.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 95,068 kB
  • sloc: php: 289,425; xml: 127,249; javascript: 112,130; python: 202; sh: 178; makefile: 20; sql: 10
file content (203 lines) | stat: -rw-r--r-- 7,556 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php

/**
 * Matomo - free/libre analytics platform
 *
 * @link    https://matomo.org
 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Plugins\DevicesDetection\tests\Fixtures;

use Piwik\Date;
use Piwik\Plugins\Goals\API;
use Piwik\Tests\Framework\Fixture;

/**
 * Fixture that adds one site with one goal and tracks some page views from different devices with some goal conversions
 */
class MultiDeviceGoalConversions extends Fixture
{
    public $dateTime = '2009-01-04 00:11:42';
    public $idSite   = 1;
    public $idGoal   = 1;

    public function setUp(): void
    {
        $this->setUpWebsitesAndGoals();
        $this->trackSmartphoneVisits();
        $this->trackTabletVisits();
        $this->trackOtherVisits();
    }

    public function tearDown(): void
    {
        // empty
    }

    private function setUpWebsitesAndGoals()
    {
        if (!self::siteCreated($idSite = 1)) {
            self::createWebsite($this->dateTime, $ecommerce = 1);
        }

        if (!self::goalExists($idSite = 1, $idGoal = 1)) {
            API::getInstance()->addGoal(
                $this->idSite,
                'Goal 1 - Thank you',
                'title',
                'Thank you',
                'contains',
                $caseSensitive = false,
                $revenue = 10,
                $allowMultipleConversions = 1
            );
        }
    }

    private function trackSmartphoneVisits()
    {
        // first visit (with conversion)
        $t = self::getTracker($this->idSite, $this->dateTime, $defaultInit = true);

        $t->setUserAgent('Mozilla/5.0 (Linux; Android 4.2.2; HTC Butterfly Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36');

        $t->setUrl('http://example.org/index.htm');
        self::checkResponse($t->doTrackPageView('0'));

        $t->setForceVisitDateTime($this->getAdjustedDateTime(0.3));

        self::checkResponse($t->doTrackGoal($this->idGoal, $revenue = 42.256));

        // second visit (without conversion)
        $t = self::getTracker($this->idSite, $this->getAdjustedDateTime(0.2), $defaultInit = true);

        $t->setUserAgent('Mozilla/5.0 (Linux; Android 4.2.2; HTC Butterfly Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36');

        $t->setUrl('http://example.org/anypage.php');
        self::checkResponse($t->doTrackPageView('mine'));


        // third visit (with conversion)
        $t = self::getTracker($this->idSite, $this->getAdjustedDateTime(0.2), $defaultInit = true);

        $t->setUserAgent('Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D167 iPhone6,1/N51AP Zite/2.6');

        $t->setUrl('http://example.org/anypage.php');
        self::checkResponse($t->doTrackPageView('mine'));

        $t->setForceVisitDateTime($this->getAdjustedDateTime(1));

        self::checkResponse($t->doTrackGoal($this->idGoal, $revenue = 0));
    }

    private function trackTabletVisits()
    {
        // first visit (with conversion)
        $t = self::getTracker($this->idSite, $this->getAdjustedDateTime(1), $defaultInit = true);

        $t->setUserAgent('Mozilla/5.0 (iPad; CPU OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) CriOS/31.0.1650.18 Mobile/10A523 Safari/8536.25');

        $t->setUrl('http://example.org/index.htm');
        self::checkResponse($t->doTrackPageView('0'));

        $t->setForceVisitDateTime($this->getAdjustedDateTime(1.6));

        self::checkResponse($t->doTrackGoal($this->idGoal, $revenue = 42.256));

        // second visit (without conversion)
        $t = self::getTracker($this->idSite, $this->getAdjustedDateTime(0.6), $defaultInit = true);

        $t->setUserAgent('Mozilla/5.0 (Linux; Android 4.2.2; SM-T310 Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.136 Safari/537.36');

        $t->setUrl('http://example.org/index.htm');
        self::checkResponse($t->doTrackPageView('0'));


        // third visit (with conversion)
        $t = self::getTracker($this->idSite, $this->getAdjustedDateTime(1.6), $defaultInit = true);

        $t->setUserAgent('Mozilla/5.0 (Linux; U; Android 2.3;en-us; ViewSonic-ViewPad7e build/ERE27) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1');

        $t->setUrl('http://example.org/anypage.php');
        self::checkResponse($t->doTrackPageView('mine'));

        $t->setForceVisitDateTime($this->getAdjustedDateTime(1.9));

        self::checkResponse($t->doTrackGoal($this->idGoal, $revenue = 0));
    }

    private function trackOtherVisits()
    {
        // unknown device visit (with conversion)
        $t = self::getTracker($this->idSite, $this->getAdjustedDateTime(1), $defaultInit = true);

        $t->setUserAgent('not detectable');

        $t->setUrl('http://example.org/anypage.php');
        self::checkResponse($t->doTrackPageView('mine'));

        $t->setForceVisitDateTime($this->getAdjustedDateTime(4));

        self::checkResponse($t->doTrackGoal($this->idGoal, $revenue = 42.256));

        // tv visit (without conversion)
        $t = self::getTracker($this->idSite, $this->getAdjustedDateTime(3), $defaultInit = true);

        $t->setUserAgent('WebKit/3.7.6, (CE-HTML/1.0 NETTV/3.3.0 NewB) PHILIPS-AVM-2013/2.19 (Philips, BDP5600, wired)');

        $t->setUrl('http://example.org/anypage.php');
        self::checkResponse($t->doTrackPageView('mine'));


        // feature phone visit (with conversion)
        $t = self::getTracker($this->idSite, $this->getAdjustedDateTime(4), $defaultInit = true);

        $t->setUserAgent('Fly_DS123/Q03C_MAUI_Browser/MIDP2.0 Configuration/CLDC-1.1');

        $t->setUrl('http://example.org/index.htm');
        self::checkResponse($t->doTrackPageView('0'));

        $t->setForceVisitDateTime($this->getAdjustedDateTime(4.2));

        self::checkResponse($t->doTrackGoal($this->idGoal, $revenue = 0));


        // desktop visit (with conversion)
        $t = self::getTracker($this->idSite, $this->getAdjustedDateTime(1.6), $defaultInit = true);

        $t->setUserAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; Banca Caboto s.p.a.; rv:11.0) like Gecko');
        // The client hints below should change the OS to Windows 11 and browser to Edge 95.5.2
        $t->setClientHints('', 'Windows', '14.0.0', '" Not A;Brand";v="99", "Chromium";v="95", "Microsoft Edge";v="95"', '95.5.2');

        $t->setUrl('http://example.org/index.htm');
        self::checkResponse($t->doTrackPageView('0'));

        $t->setForceVisitDateTime($this->getAdjustedDateTime(1.9));

        self::checkResponse($t->doTrackGoal($this->idGoal, $revenue = 0));

        // car browser visit (without conversion)
        $t = self::getTracker($this->idSite, $this->getAdjustedDateTime(1.8), $defaultInit = true);

        $t->setUserAgent('Some Unknown UA');
        // The client hints below should change the OS to Android, browser to Chrome 95.5.2 and device type to car browser
        $t->setClientHints(
            'UltraOcta-T8',
            'Android',
            '14.0.0',
            '" Not A;Brand";v="99", "Chromium";v="95"',
            '95.5.2',
            '"Tablet", "Automotive"'
        );

        $t->setUrl('http://example.org/index.htm');
        self::checkResponse($t->doTrackPageView('0'));
    }


    private function getAdjustedDateTime($addition)
    {
        return Date::factory($this->dateTime)->addHour($addition)->getDatetime();
    }
}