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
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Fixtures;
use Piwik\Date;
use Piwik\Plugins\Goals\API;
use Piwik\Tests\Framework\Fixture;
/**
* Fixture that adds one site with three goals and tracks one pageview & one manual
* goal conversion.
*/
class ThreeGoalsOnePageview extends Fixture
{
public $dateTime = '2009-01-04 00:11:42';
public $idSite = 1;
public $idGoal = 1;
public $idGoal2 = 2;
public $idGoal3 = 3;
public function setUp(): void
{
Fixture::createSuperUser();
$this->setUpWebsitesAndGoals();
$this->trackVisits();
}
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
);
}
if (!self::goalExists($idSite = 1, $idGoal = 2)) {
API::getInstance()->addGoal(
$this->idSite, 'Goal 2 - Hello', 'url', 'hellow', 'contains', $caseSensitive = false,
$revenue = 10, $allowMultipleConversions = 0
);
}
if (!self::goalExists($idSite = 1, $idGoal = 3)) {
API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', '');
}
}
private function trackVisits()
{
$t = self::getTracker($this->idSite, $this->dateTime, $defaultInit = true);
// Record 1st page view
$t->setUrl('http://example.org/index.htm');
self::checkResponse($t->doTrackPageView('0'));
$t->setForceVisitDateTime(Date::factory($this->dateTime)->addHour(0.3)->getDatetime());
self::checkResponse($t->doTrackGoal($this->idGoal3, $revenue = 42.256));
}
}
|