-
Notifications
You must be signed in to change notification settings - Fork 19
/
MarketingCampaignsReporting.php
123 lines (106 loc) · 4.81 KB
/
MarketingCampaignsReporting.php
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
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* Based on code from AdvancedCampaignReporting plugin by Piwik PRO released under GPL v3 or later:
* https://github.com/PiwikPRO/plugin-AdvancedCampaignReporting
*/
namespace Piwik\Plugins\MarketingCampaignsReporting;
use Piwik\Container\StaticContainer;
use Piwik\Db;
use Piwik\Plugin;
use Piwik\Plugin\Report;
use Piwik\Plugins\MarketingCampaignsReporting\Columns\Base;
use Piwik\Plugins\Referrers\Reports\GetCampaigns;
/**
* @package MarketingCampaignsReporting
*/
class MarketingCampaignsReporting extends Plugin
{
public static $CAMPAIGN_NAME_FIELD_DEFAULT_URL_PARAMS = array('mtm_campaign', 'matomo_campaign', 'mtm_cpn', 'pk_campaign', 'piwik_campaign', 'pk_cpn', 'utm_campaign');
public static $CAMPAIGN_KEYWORD_FIELD_DEFAULT_URL_PARAMS = array('mtm_keyword', 'matomo_kwd', 'mtm_kwd', 'pk_keyword', 'piwik_kwd', 'pk_kwd', 'utm_term');
public static $CAMPAIGN_SOURCE_FIELD_DEFAULT_URL_PARAMS = array('mtm_source', 'pk_source', 'utm_source');
public static $CAMPAIGN_MEDIUM_FIELD_DEFAULT_URL_PARAMS = array('mtm_medium', 'pk_medium', 'utm_medium');
public static $CAMPAIGN_CONTENT_FIELD_DEFAULT_URL_PARAMS = array('mtm_content', 'pk_content', 'utm_content');
public static $CAMPAIGN_ID_FIELD_DEFAULT_URL_PARAMS = array('mtm_cid', 'pk_cid', 'utm_id', 'mtm_clid');
public static $CAMPAIGN_GROUP_FIELD_DEFAULT_URL_PARAMS = array('mtm_group', 'pk_group');
public static $CAMPAIGN_PLACEMENT_FIELD_DEFAULT_URL_PARAMS = array('mtm_placement', 'pk_placement');
public function registerEvents()
{
return array(
'Tracker.PageUrl.getQueryParametersToExclude' => 'getQueryParametersToExclude',
'Report.filterReports' => 'removeOriginalCampaignReport',
'Insights.addReportToOverview' => 'addReportToInsightsOverview',
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
);
}
public function getStylesheetFiles(&$stylesheets)
{
$stylesheets[] = "plugins/MarketingCampaignsReporting/stylesheets/styles.less";
}
public function install()
{
$tables = \Piwik\DbHelper::getTablesInstalled();
foreach ($tables as $tableName) {
if (strpos($tableName, 'archive_blob_') !== false || strpos($tableName, 'archive_numeric_') !== false) {
Db::exec('UPDATE `' . $tableName . '` SET `name`=REPLACE(`name`, \'AdvancedCampaignReporting_\', \'MarketingCampaignsReporting_\') WHERE `name` LIKE \'AdvancedCampaignReporting_%\'');
}
}
Plugin\Manager::getInstance()->deactivatePlugin('AdvancedCampaignReporting');
}
public function getQueryParametersToExclude(&$excludedParameters)
{
$advancedCampaignParameters = self::getCampaignParameters();
foreach ($advancedCampaignParameters as $advancedCampaignParameter) {
$excludedParameters = array_merge($excludedParameters, $advancedCampaignParameter);
}
}
public function addReportToInsightsOverview(&$reports)
{
unset($reports['Referrers_getCampaigns']);
$reports['MarketingCampaignsReporting_getName'] = [];
}
/**
* @return array
*/
public static function getCampaignParameters()
{
return array_merge(
StaticContainer::get('advanced_campaign_reporting.uri_parameters.campaign_name'),
StaticContainer::get('advanced_campaign_reporting.uri_parameters.campaign_keyword'),
StaticContainer::get('advanced_campaign_reporting.uri_parameters.campaign_source'),
StaticContainer::get('advanced_campaign_reporting.uri_parameters.campaign_medium'),
StaticContainer::get('advanced_campaign_reporting.uri_parameters.campaign_content'),
StaticContainer::get('advanced_campaign_reporting.uri_parameters.campaign_id'),
StaticContainer::get('advanced_campaign_reporting.uri_parameters.campaign_group'),
StaticContainer::get('advanced_campaign_reporting.uri_parameters.campaign_placement')
);
}
/**
* @param Report[] $reports
*/
public function removeOriginalCampaignReport(&$reports)
{
foreach ($reports as $index => $report) {
if ($report instanceof GetCampaigns) {
unset($reports[$index]);
}
}
}
public static function getAdvancedCampaignFields()
{
$dimensions = Base::getDimensions(new self());
$campaignFields = [];
foreach ($dimensions as $dimension) {
$campaignFields[] = $dimension->getColumnName();
}
return $campaignFields;
}
public function isTrackerPlugin()
{
return true;
}
}