File: MultipleSitesMultipleVisitsFixture.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 (584 lines) | stat: -rw-r--r-- 21,883 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
<?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\PrivacyManager\tests\Fixtures;

use Piwik\Common;
use Piwik\DataAccess\ArchiveTableCreator;
use Piwik\DataAccess\ArchiveWriter;
use Piwik\Date;
use Piwik\Db;
use Piwik\DbHelper;
use Piwik\Period\Day;
use Piwik\Period\Month;
use Piwik\Period\Week;
use Piwik\Period\Year;
use Piwik\Piwik;
use Piwik\Plugins\UserCountry\LocationProvider;
use Piwik\Tests\Framework\Fixture;
use Piwik\Plugins\Goals\API as ApiGoals;
use Piwik\Tracker\LogTable;
use Piwik\Tests\Framework\Mock\LocationProvider as MockLocationProvider;

require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Framework/Mock/LocationProvider.php';


class TestLogFooBarBaz extends LogTable
{
    public const TABLE = 'log_foo_bar_baz';

    public function install()
    {
        DbHelper::createTable($this->getName(), "
                  `idlogfoobarbaz` bigint(15) NOT NULL,
                  `idlogfoobar` bigint(15) NOT NULL");
    }

    public function uninstall()
    {
        Db::query(sprintf('DROP TABLE IF EXISTS `%s`', Common::prefixTable($this->getName())));
    }

    public function insertEntry($idLogFooBarBaz, $idLogFooBar)
    {
        Db::query(sprintf('INSERT INTO `%s` VALUES(?,?)', Common::prefixTable($this->getName())), array($idLogFooBarBaz, $idLogFooBar));
    }

    public function getName()
    {
        return self::TABLE;
    }

    public function getIdColumn()
    {
        return 'idlogfoobarbaz';
    }

    public function getWaysToJoinToOtherLogTables()
    {
        return array('log_foo_bar' => 'idlogfoobar');
    }
}

class TestLogFooBar extends LogTable
{
    public const TABLE = 'log_foo_bar';

    public function install()
    {
        DbHelper::createTable($this->getName(), "
                  `idlogfoobar` bigint(15) NOT NULL,
                  `idlogfoo` bigint(15) NOT NULL");
    }

    public function insertEntry($idLogFooBar, $idLogFoo)
    {
        Db::query(sprintf('INSERT INTO `%s` VALUES(?,?)', Common::prefixTable($this->getName())), array($idLogFooBar, $idLogFoo));
    }

    public function uninstall()
    {
        Db::query(sprintf('DROP TABLE IF EXISTS `%s`', Common::prefixTable($this->getName())));
    }

    public function getName()
    {
        return self::TABLE;
    }

    public function getIdColumn()
    {
        return 'idlogfoobar';
    }

    public function getWaysToJoinToOtherLogTables()
    {
        return array('log_foo' => 'idlogfoo');
    }
}

class TestLogFoo extends LogTable
{
    public const TABLE = 'log_foo';

    public function install()
    {
        DbHelper::createTable($this->getName(), "
                  `idlogfoo` bigint(15) NOT NULL,
                  `idsite` bigint(15) NOT NULL,
                  `idvisit` bigint(15) NOT NULL");
    }

    public function insertEntry($idLogFoo, $idSite, $idVisit)
    {
        Db::query(sprintf('INSERT INTO `%s` VALUES(?,?,?)', Common::prefixTable($this->getName())), array($idLogFoo, $idSite, $idVisit));
    }

    public function uninstall()
    {
        Db::query(sprintf('DROP TABLE IF EXISTS `%s`', Common::prefixTable($this->getName())));
    }

    public function getColumnToJoinOnIdVisit()
    {
        return 'idvisit';
    }

    public function getName()
    {
        return self::TABLE;
    }

    public function getIdColumn()
    {
        return 'idlogfoo';
    }
}


class MultipleSitesMultipleVisitsFixture extends Fixture
{
    private static $countryCode = array(
        'CA', 'CN', 'DE', 'ES', 'FR', 'IE', 'IN', 'IT', 'MX', 'PT', 'RU', 'GB', 'US',
    );

    private static $performanceTimes = [
        // [$network, $server, $transfer, $domProcessing, $domCompletion, $onload]
        [26, 235, 36, 199, 155, 90],
        [null, null, null, null, null, null],
        [0, 365, 66, 256, 201, 105],
        [0, 406, 105, 405, 122, 23],
        [99, 110, 248, 321, 369, 201],
        [106, 198, 168, 216, 188, 165],
        [306, 200, 405, 169, 208, 99],
        [null, null, null, null, null, null],
        [36, 99, 206, 165, 359, 155],
    ];

    private static $searchKeyword = array('piwik', 'analytics', 'web', 'mobile', 'ecommerce', 'custom');
    private static $searchCategory = array('', '', 'video', 'images', 'web', 'web');

    public $dateTime = '2017-01-02 03:04:05';
    public $trackingTime = '2017-01-02 03:04:05';
    public $idSite = 1;
    public $numVisitsPerIteration = 32;
    /**
     * @var \MatomoTracker
     */
    private $tracker;

    private $numSites = 5;
    private $currentUserId;

    public function setUp(): void
    {
        parent::setUp();
        $this->installLogTables();
        $this->setUpWebsites();
        $this->setUpLocation();
        $this->trackVisitsForMultipleSites();
    }

    public function tearDown(): void
    {
        $this->tearDownLocation();
    }

    public function tearDownLocation()
    {
        LocationProvider::$providers = null;
    }

    public function setUpLocation()
    {
        $mock = new MockLocationProvider();
        LocationProvider::$providers = array($mock);
        LocationProvider::setCurrentProvider('mock_provider');
        MockLocationProvider::$locations = array(
            self::makeLocation('Stratford-upon-Avon', 'P3', 'gb', 123.456, 21.321), // template location

            // same region, different city, same country
            self::makeLocation('Nuneaton and Bedworth', 'P3', 'gb', $isp = 'comcast.net'),

            // same region, city & country (different lat/long)
            self::makeLocation('Stratford-upon-Avon', 'P3', 'gb', 124.456, 22.231, $isp = 'comcast.net'),

            // same country, different region & city
            self::makeLocation('London', 'H9', 'gb'),

            // same country, different region, same city
            self::makeLocation('Stratford-upon-Avon', 'G5', 'gb', $lat = null, $long = null, $isp = 'awesomeisp.com'),

            // different country, diff region, same city
            self::makeLocation('Stratford-upon-Avon', '66', 'ru'),

            // different country, diff region (same as last), different city
            self::makeLocation('Hluboká nad Vltavou', '66', 'ru'),

            // different country, diff region (same as last), same city
            self::makeLocation('Stratford-upon-Avon', '66', 'mk'),
        );
    }

    public function installLogTables()
    {
        try {
            $columns = DbHelper::getTableColumns(TestLogFoo::TABLE);
            if (!empty($columns)) {
                return; // already installed
            }
        } catch (\Exception $e) {
            // not installed yet
        }
        $extraLogTables = array(new TestLogFooBar(), new TestLogFoo(), new TestLogFooBarBaz());
        foreach ($extraLogTables as $extraLogTable) {
            $extraLogTable->install();
        }

        Piwik::addAction('LogTables.addLogTables', function (&$logTables) use ($extraLogTables) {
            foreach ($extraLogTables as $extraLogTable) {
                $logTables[] = $extraLogTable;
            }
        });
    }

    public function uninstallLogTables()
    {
        $extraLogTables = array(new TestLogFooBar(), new TestLogFoo(), new TestLogFooBarBaz());
        foreach ($extraLogTables as $extraLogTable) {
            $extraLogTable->uninstall();
        }
    }

    private function trackVisitsForMultipleSites()
    {
        $this->trackVisits($idSite = 1, $numIterationsDifferentDays = 4);
        $this->trackVisits($idSite = 3, $numIterationsDifferentDays = 1);
        $this->trackVisits($idSite = 5, $numIterationsDifferentDays = 2);
    }

    public function setUpWebsites()
    {
        Fixture::createSuperUser(false);

        // we make sure by default nothing is anonymized
        $privacyConfig = new \Piwik\Plugins\PrivacyManager\Config();
        $privacyConfig->ipAddressMaskLength = 0;
        $privacyConfig->ipAnonymizerEnabled = false;

        for ($siteid = 1; $siteid <= $this->numSites; $siteid++) {
            if (!self::siteCreated($siteid)) {
                $idSite = self::createWebsite('2014-01-02 03:04:05', $ecommerce = 1, 'Site ' . $siteid);
                $this->assertSame($siteid, $idSite);

                $this->createGoals($idSite, 2);
                if ($idSite === 3) {
                    $this->setSiteVisitorLogsDisabled($idSite);
                }
            }
        }
    }

    private function setSiteVisitorLogsDisabled($idSite)
    {
        $settings = new \Piwik\Plugins\Live\MeasurableSettings($idSite);
        $settings->disableVisitorLog->setValue(true);
        $settings->save();
    }

    public function createGoals($idSite, $numGoals)
    {
        $numGoals = range(1, $numGoals);

        $patterns = array(
            1 => '/path/1',
            2 => '/path/2',
        );
        $api = ApiGoals::getInstance();
        foreach ($numGoals as $idGoal) {
            if (!self::goalExists($idSite, $idGoal)) {
                $matchAttribute = 'url';
                $patternType = 'contains';
                $name = 'Goal ' . $idGoal;
                $caseSensitive = false;

                $pattern = 'fooBar';
                if (isset($patterns[$idGoal])) {
                    $pattern = $patterns[$idGoal];
                }

                $revenue = '0';

                $api->addGoal($idSite, $name, $matchAttribute, $pattern, $patternType, $caseSensitive, $revenue);
            }
        }
    }

    public function insertOtherLogTableData($idSite)
    {
        $idMultiplier = $idSite - 1;
        $toAddToId = $idMultiplier * 100;

        $idVisits = Db::fetchAll('SELECT idvisit FROM ' . Common::prefixTable('log_visit') . ' WHERE idsite = ? ORDER BY idvisit ASC LIMIT 2', [$idSite]);
        $idVisits = array_column($idVisits, 'idvisit');

        $this->installLogTables();
        $logFoo = new TestLogFoo();
        $logFoo->insertEntry(10 + $toAddToId, $idSite, $idVisits[0]);
        $logFoo->insertEntry(21 + $toAddToId, $idSite, $idVisits[0]);
        $logFoo->insertEntry(22 + $toAddToId, $idSite, $idVisits[1]);

        $logFooBar = new TestLogFooBar();
        $logFooBar->insertEntry(35 + $toAddToId, 10 + $toAddToId);
        $logFooBar->insertEntry(36 + $toAddToId, 10 + $toAddToId);
        $logFooBar->insertEntry(37 + $toAddToId, 22 + $toAddToId);

        $logFooBar = new TestLogFooBarBaz();
        $logFooBar->insertEntry(51 + $toAddToId, 35 + $toAddToId);
        $logFooBar->insertEntry(52 + $toAddToId, 36 + $toAddToId);
    }

    public function insertArchiveRows($idSite, $numVisits)
    {
        for ($day = 0; $day < $numVisits; $day++) {
            $archiveDate = Date::factory($this->dateTime);
            if ($day > 0) {
                $archiveDate = $archiveDate->addDay($day * 3);
            }
            $doneRow = array(
                'idarchive' => ($idSite * 100) + ($day * 10) + 1,
                'idsite' => $idSite,
                'name' => 'done',
                'value' => ArchiveWriter::DONE_OK,
                'date1' => $archiveDate->toString('Y-m-d'),
                'date2' => $archiveDate->toString('Y-m-d'),
                'period' => 1,
                'ts_archived' => $archiveDate->getDatetime(),
            );
            $this->insertArchiveRow($archiveDate, $doneRow);
        }
    }

    private function insertArchiveRow($date, $row)
    {
        $table = ArchiveTableCreator::getNumericTable($date);
        $sql = "INSERT INTO `%s` (idarchive, idsite, name, value, date1, date2, period, ts_archived) VALUES ('%s')";

        $row['period'] = Day::PERIOD_ID;
        Db::exec(sprintf($sql, $table, implode("','", $row)));

        $row['period'] = Week::PERIOD_ID;
        $row['idarchive']++;
        Db::exec(sprintf($sql, $table, implode("','", $row)));

        $row['period'] = Month::PERIOD_ID;
        $row['idarchive']++;
        Db::exec(sprintf($sql, $table, implode("','", $row)));

        $row['period'] = Year::PERIOD_ID;
        $row['idarchive']++;
        Db::exec(sprintf($sql, $table, implode("','", $row)));
    }

    public function trackVisits($idSite, $numIterations)
    {
        for ($day = 0; $day < $numIterations; $day++) {
            // we track over several days to make sure we have some data to aggregate in week reports
            // NOTE: some action times are out of order in visits on purpose
            //       the first iteration always uses the tracking time of the previous site

            if ($day > 0) {
                $this->trackingTime = Date::factory($this->dateTime)->addDay($day * 3)->getDatetime();
            }

            // track visits for each site without overlapping times
            $this->trackingTime = Date::factory($this->trackingTime)->subSeconds($idSite)->getDateTime();

            $this->tracker = self::getTracker($idSite, $this->trackingTime, $defaultInit = true);
            $this->tracker->enableBulkTracking();
            $this->tracker->setUserAgent('Mozilla/5.0 (Windows NT 6.0; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.66 Safari/535.11');

            $this->trackVisit($userId = 200, 'http://www.example.com/', $idGoal = 1, $hoursAgo = null);
            $this->doTrack();

            $this->trackVisit($userId = 201, 'http://www.google.com?q=test', $idGoal = null, $hoursAgo = 2);
            $this->trackVisit($userId = 201, 'http://www.example.com/', $idGoal = 2);
            $this->doTrack();

            $this->trackVisit($userId = 202, null, $idGoal = null, $hoursAgo = 43);
            $this->trackVisit($userId = 202, 'http://www.google.com?q=test', $idGoal = null, $hoursAgo = 4);
            $this->trackVisit($userId = 202, 'http://www.example.com/', $idGoal = 1);
            $this->doTrack();

            $this->trackVisit($userId = 203, null, $idGoal = null, $hoursAgo = 43);
            $this->trackVisit($userId = 203, 'http://www.example.com', $idGoal = null, $hoursAgo = 18);
            $this->trackVisit($userId = 203, 'http://www.facebook.com/foo', $idGoal = null, $hoursAgo = 13);
            $this->trackVisit($userId = 203, null, $idGoal = null, $hoursAgo = 8);
            $this->trackVisit($userId = 203, 'http://www.matomo.org', $idGoal = null, $hoursAgo = 3);
            $this->trackVisit($userId = 203, 'http://www.google.com?q=test', $idGoal = null, $hoursAgo = 1);
            $this->trackVisit($userId = 203, 'http://www.innocraft.com', $idGoal = 1);

            $this->trackVisit($userId = 204, 'http://developer.matomo.org', $idGoal = 2);

            $this->trackVisit($userId = 205, 'http://www.matomo.org', $idGoal = null, $hoursAgo = 3);
            $this->trackVisit($userId = 205, null, $idGoal = 1);

            $this->trackVisit($userId = 206, 'http://ios.matomo.org', $idGoal = null, $hoursAgo = 2);
            $this->trackVisit($userId = 206, null, $idGoal = null, $hoursAgo = 5);
            $this->trackVisit($userId = 206, 'http://www.facebook.com/bar', $idGoal = null, $hoursAgo = 3);
            $this->trackVisit($userId = 206, null, $idGoal = 2);

            $this->trackVisit($userId = 207, 'http://hello.example.com', $idGoal = null, $hoursAgo = 3);
            $this->trackVisit($userId = 207, null, $idGoal = null, $hoursAgo = null);

            $this->trackVisit($userId = 208, 'http://example.matomo.org/mypath', $idGoal = null, $hoursAgo = 8);
            $this->trackVisit($userId = 208, null, $idGoal = null, $hoursAgo = null);
            $this->doTrack();

            $this->trackVisit($userId = 209, 'http://www.facebook.com/bar', $idGoal = null, $hoursAgo = 2);
            $this->trackVisit($userId = 209, null, $idGoal = 1);

            $this->trackVisit($userId = 210, null, $idGoal = 1, $hoursAgo = null);

            $this->trackVisit($userId = 211, 'http://developer.matomo.org?x=1', $idGoal = null, $hoursAgo = 1);
            $this->trackVisit($userId = 211, null, $idGoal = 2, $hoursAgo = 13);
            $this->trackVisit($userId = 211, null, $idGoal = 1, $hoursAgo = 10);
            $this->trackVisit($userId = 211, null, $idGoal = null, $hoursAgo = 4);
            $this->trackVisit($userId = 211, null, $idGoal = 1);
            $this->doTrack();
        }

        if ($idSite == 1) {
            $this->insertOtherLogTableData($idSite);
        }
    }

    private function doTrack()
    {
        self::checkBulkTrackingResponse($this->tracker->doBulkTrack());
    }

    private function initTracker($userId, $hoursAgo = null)
    {
        if (!empty($hoursAgo)) {
            $time = Date::factory($this->trackingTime)->subHour($hoursAgo)->getDatetime();
        } else {
            $time = $this->trackingTime;
        }
        $this->tracker->setForceNewVisit();
        $this->tracker->setIp('156.5.3.' . $userId);
        $this->tracker->setUserId('userId' . $userId);
        $this->tracker->setVisitorId(substr(md5('userId' . $userId), 0, 16)); // predictable visitor ID for tests
        $this->tracker->setForceVisitDateTime($time);
        $this->tracker->setCustomVariable(1, 'myCustomUserId', $userId, 'visit');
        $this->tracker->setTokenAuth(Fixture::getTokenAuth());

        if (($userId % 10) < 9) {
            $this->tracker->setBrowserHasCookies(true);
        } else {
            $this->tracker->setBrowserHasCookies(false);
        }

        $numCountries = count(self::$countryCode);
        $this->tracker->setCountry(strtolower(self::$countryCode[$userId % $numCountries]));
    }

    private function trackVisit($userId, $referrer, $idGoal = null, $hoursAgo = null)
    {
        $this->initTracker($userId, $hoursAgo);
        $this->tracker->setUrlReferrer($referrer ?? false);
        $this->tracker->setUrl('http://www.helloworld.com/hello/world' . $userId);
        $this->tracker->doTrackPageView('Hello World ');

        if (isset($idGoal)) {
            $this->tracker->doTrackGoal($idGoal);
        }

        $numAdditionalPageviews = $userId % 3;
        for ($j = 0; $j < $numAdditionalPageviews; $j++) {
            $trackingTime = Date::factory($this->trackingTime)->subHour($hoursAgo)->addHour(0.1)->getDatetime();
            $this->tracker->setForceVisitDateTime($trackingTime);
            $this->tracker->setUrl('http://www.helloworld.com/hello/world' . $userId . '/' . $j);

            $numPerformanceTimes = count(self::$performanceTimes);
            call_user_func_array([$this->tracker, 'setPerformanceTimings'], self::$performanceTimes[($userId + $j) % $numPerformanceTimes]);

            $this->tracker->doTrackPageView('Hello World ' . $j);
        }

        if ($this->currentUserId === $userId) {
            return;
        }

        // we only want to do this once per user
        $this->currentUserId = $userId;

        $userIdHoursAgo = $userId + ($hoursAgo ? $hoursAgo : 1); // bring in more randomness

        if ($userId % 5 === 0) {
            $numKeywords = count(self::$searchKeyword);
            $keyword = strtolower(self::$searchKeyword[$userIdHoursAgo % $numKeywords]);

            $numCategories = count(self::$searchCategory);
            $category = strtolower(self::$searchCategory[$userIdHoursAgo % $numCategories]);

            $this->tracker->doTrackSiteSearch($keyword, $category, $userId);
        }

        if ($userId % 4 === 0) {
            $this->tracker->doTrackContentImpression('Product 1', '/path/product1.jpg', 'http://product1.example.com');
            $this->tracker->doTrackContentImpression('Product 1', 'Buy Product 1 Now!', 'http://product1.example.com');
            $this->tracker->doTrackContentImpression('Product 2', '/path/product2.jpg', 'http://product' . $userId . '.example.com');
            $this->tracker->doTrackContentImpression('Product 3', 'Product 3 on sale', 'http://product3.example.com');
            $this->tracker->doTrackContentImpression('Product 4');
            $this->tracker->doTrackContentInteraction('click', 'Product 3', 'Product 3 on sale', 'http://product3.example.com');
            $this->tracker->doTrackContentInteraction('hover', '/path/product1.jpg', 'http://product1.example.com');
        }

        if ($userId % 3 === 1) {
            $this->tracker->addEcommerceItem($sku = $userId, 'My product ' . $userId, 'Sound Category', $price = $userId, 1);

            if ($userId % 2 === 0) {
                $this->tracker->doTrackEcommerceCartUpdate(50);
            } else {
                $subtotal = $price * 1;
                $tax = $subtotal * 0.21;
                $shipping = $subtotal * 0.07;
                $discount = $subtotal * 0.14;
                $grandTotal = $subtotal + $shipping + $tax - $discount;
                $this->tracker->doTrackEcommerceOrder($userId, $grandTotal, $subtotal, $tax, $shipping, $discount);
            }
        }

        if ($userId % 3 === 0) {
            $this->tracker->doTrackEvent('Sound', 'play', 'Test Name', 2);
            $this->tracker->doTrackEvent('Sound', 'play', 'My Sound', 3);
            $this->tracker->doTrackEvent('Sound', 'stop', 'My Sound', 1);
            $this->tracker->doTrackEvent('Sound', 'resume', 'Another Sound');
            $this->tracker->doTrackEvent('Sound', 'play');
        }
    }

    public static function cleanResult($result)
    {
        if (!empty($result) && is_array($result)) {
            foreach ($result as $key => $value) {
                if (is_array($value)) {
                    $result[$key] = self::cleanResult($value);
                } elseif ($key === 'idpageview') {
                    $result[$key] = '123456';
                } elseif ($value !== null && !is_bool($value)) {
                    $result[$key] = (string) $result[$key]; // PDO and MySQLI might return different types
                }
            }
        }

        return $result;
    }
}