Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Advertising.php « PiwikPro « core - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: deea4fa9f37f8c24e2c6daaee166ed140ed3ee73 (plain)
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
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
namespace Piwik\PiwikPro;

use Piwik\Plugin;
use Piwik\Config;

/**
 * Piwik PRO Advertising related methods. Lets you for example check whether advertising is enabled, generate
 * links for differnt landing pages etc.
 *
 * @api
 * @since 2.16.0
 */
class Advertising
{
    const CAMPAIGN_NAME_UPGRADE_TO_PRO = 'Upgrade_to_Pro';
    const CAMPAIGN_NAME_UPGRADE_TO_CLOUD = 'Upgrade_to_Cloud';

    /**
     * @var Plugin\Manager
     */
    private $pluginManager;

    /**
     * @var Config
     */
    private $config;

    public function __construct(Plugin\Manager $pluginManager, Config $config)
    {
        $this->pluginManager = $pluginManager;
        $this->config = $config;
    }

    /**
     * Returns true if it is ok to show some Piwik PRO advertising in the Piwik UI.
     * @return bool
     */
    public function arePiwikProAdsEnabled()
    {
        if ($this->pluginManager->isPluginActivated('EnterpriseAdmin')
            || $this->pluginManager->isPluginActivated('LoginAdmin')
            || $this->pluginManager->isPluginActivated('CloudAdmin')
            || $this->pluginManager->isPluginActivated('WhiteLabel')) {
            return false;
        }

        $showAds = $this->config->General['piwik_pro_ads_enabled'];

        return !empty($showAds);
    }

    /**
     * Get URL for promoting the Piwik Cloud.
     *
     * @param string $campaignMedium
     * @param string $campaignContent
     * @return string
     */
    public function getPromoUrlForCloud($campaignMedium, $campaignContent = '')
    {
        $url = 'https://piwik.pro/cloud/?';

        $campaign = $this->getCampaignParametersForPromoUrl(
            $name = self::CAMPAIGN_NAME_UPGRADE_TO_CLOUD,
            $campaignMedium,
            $campaignContent
        );

        return $url . $campaign;
    }

    /**
     * Get URL for promoting Piwik On Premises.
     * @param string $campaignMedium
     * @param string $campaignContent
     * @return string
     */
    public function getPromoUrlForOnPremises($campaignMedium, $campaignContent = '')
    {
        $url = 'https://piwik.pro/c/upgrade/?';

        $campaign = $this->getCampaignParametersForPromoUrl(
            $name = self::CAMPAIGN_NAME_UPGRADE_TO_PRO,
            $campaignMedium,
            $campaignContent
        );

        return $url . $campaign;
    }

    /**
     * Appends campaign parameters to the given URL for promoting any Piwik PRO service.
     * @param string $url
     * @param string $campaignName
     * @param string $campaignMedium
     * @param string $campaignContent
     * @return string
     */
    public function addPromoCampaignParametersToUrl($url, $campaignName, $campaignMedium, $campaignContent = '')
    {
        if (empty($url)) {
            return '';
        }

        if (strpos($url, '?') === false) {
            $url .= '?';
        } else {
            $url .= '&';
        }

        $url .= $this->getCampaignParametersForPromoUrl($campaignName, $campaignMedium, $campaignContent);

        return $url;
    }

    /**
     * Generates campaign URL parameters that can be used with any promotion link for Piwik PRO.
     *
     * @param string $campaignName
     * @param string $campaignMedium
     * @param string $campaignContent Optional
     * @return string URL parameters without a leading ? or &
     */
    private function getCampaignParametersForPromoUrl($campaignName, $campaignMedium, $campaignContent = '')
    {
        $campaignName = sprintf('pk_campaign=%s&pk_medium=%s&pk_source=Piwik_App', $campaignName, $campaignMedium);

        if (!empty($campaignContent)) {
            $campaignName .= '&pk_content=' . $campaignContent;
        }

        return $campaignName;
    }
}