File: Archiver.php

package info (click to toggle)
matomo 5.5.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 73,596 kB
  • sloc: php: 231,041; javascript: 102,286; python: 202; xml: 189; sh: 172; makefile: 20; sql: 10
file content (118 lines) | stat: -rw-r--r-- 3,593 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
<?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\Goals;

use Piwik\Plugins\VisitFrequency\API as VisitFrequencyAPI;

class Archiver extends \Piwik\Plugin\Archiver
{
    public const VISITS_UNTIL_RECORD_NAME = 'visits_until_conv';
    public const DAYS_UNTIL_CONV_RECORD_NAME = 'days_until_conv';
    public const ITEMS_SKU_RECORD_NAME = 'Goals_ItemsSku';
    public const ITEMS_NAME_RECORD_NAME = 'Goals_ItemsName';
    public const ITEMS_CATEGORY_RECORD_NAME = 'Goals_ItemsCategory';
    public const SKU_FIELD = 'idaction_sku';
    public const NAME_FIELD = 'idaction_name';
    public const CATEGORY_FIELD = 'idaction_category';
    public const CATEGORY2_FIELD = 'idaction_category2';
    public const CATEGORY3_FIELD = 'idaction_category3';
    public const CATEGORY4_FIELD = 'idaction_category4';
    public const CATEGORY5_FIELD = 'idaction_category5';
    public const NO_LABEL = ':';
    public const LOG_CONVERSION_TABLE = 'log_conversion';
    public const VISITS_COUNT_FIELD = 'visitor_count_visits';
    public const SECONDS_SINCE_FIRST_VISIT_FIELD = 'visitor_seconds_since_first';

    public function getDependentSegmentsToArchive(): array
    {
        $hasConversions = $this->getProcessor()->getNumberOfVisitsConverted() > 0;
        if (!$hasConversions) {
            return [];
        }

        return [
            VisitFrequencyAPI::NEW_VISITOR_SEGMENT,
            VisitFrequencyAPI::RETURNING_VISITOR_SEGMENT,
        ];
    }

    /**
     * This array stores the ranges to use when displaying the 'visits to conversion' report
     */
    public static $visitCountRanges = [
        [1, 1],
        [2, 2],
        [3, 3],
        [4, 4],
        [5, 5],
        [6, 6],
        [7, 7],
        [8, 8],
        [9, 14],
        [15, 25],
        [26, 50],
        [51, 100],
        [100],
    ];

    /**
     * This array stores the ranges to use when displaying the 'days to conversion' report
     */
    public static $daysToConvRanges = [
        [0, 0],
        [1, 1],
        [2, 2],
        [3, 3],
        [4, 4],
        [5, 5],
        [6, 6],
        [7, 7],
        [8, 14],
        [15, 30],
        [31, 60],
        [61, 120],
        [121, 364],
        [364],
    ];

    protected $dimensionRecord = [
        self::SKU_FIELD      => self::ITEMS_SKU_RECORD_NAME,
        self::NAME_FIELD     => self::ITEMS_NAME_RECORD_NAME,
        self::CATEGORY_FIELD => self::ITEMS_CATEGORY_RECORD_NAME,
    ];
    protected $actionMapping = [
        self::SKU_FIELD      => 'idaction_product_sku',
        self::NAME_FIELD     => 'idaction_product_name',
        self::CATEGORY_FIELD => 'idaction_product_cat',
        self::CATEGORY2_FIELD => 'idaction_product_cat2',
        self::CATEGORY3_FIELD => 'idaction_product_cat3',
        self::CATEGORY4_FIELD => 'idaction_product_cat4',
        self::CATEGORY5_FIELD => 'idaction_product_cat5',
    ];

    /**
     * @param string $recordName 'nb_conversions'
     * @param int|bool $idGoal idGoal to return the metrics for, or false to return overall
     * @return string Archive record name
     */
    public static function getRecordName($recordName, $idGoal = false)
    {
        $idGoalStr = '';
        if ($idGoal !== false) {
            $idGoalStr = $idGoal . "_";
        }
        return 'Goal_' . $idGoalStr . $recordName;
    }

    public static function getItemRecordNameAbandonedCart($recordName)
    {
        return $recordName . '_Cart';
    }
}