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
|
<?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\Plugins\Referrers;
use Piwik\Common;
use Piwik\Piwik;
use Piwik\Plugins\Referrers\Reports\Get;
use Piwik\Plugins\SitesManager\SiteUrls;
/**
* @see plugins/Referrers/functions.php
*/
require_once PIWIK_INCLUDE_PATH . '/plugins/Referrers/functions.php';
/**
*/
class Referrers extends \Piwik\Plugin
{
/**
* @see \Piwik\Plugin::registerEvents
*/
public function registerEvents()
{
return array(
'Insights.addReportToOverview' => 'addReportToInsightsOverview',
'Request.getRenamedModuleAndAction' => 'renameDeprecatedModuleAndAction',
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
'Tracker.setTrackerCacheGeneral' => 'setTrackerCacheGeneral',
'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'API.getPagesComparisonsDisabledFor' => 'getPagesComparisonsDisabledFor',
'Metrics.getDefaultMetricTranslations' => 'getDefaultMetricTranslations',
);
}
public function getDefaultMetricTranslations(&$translations)
{
$translations['Referrers_visitorsFromSearchEngines'] = Piwik::translate('Referrers_VisitorsFromSearchEngines');
$translations['Referrers_visitorsFromSearchEngines_percent'] = Piwik::translate('Referrers_PercentOfX', $translations['Referrers_visitorsFromSearchEngines']);
$translations['Referrers_visitorsFromSocialNetworks'] = Piwik::translate('Referrers_VisitorsFromSocialNetworks');
$translations['Referrers_visitorsFromSocialNetworks_percent'] = Piwik::translate('Referrers_PercentOfX', $translations['Referrers_visitorsFromSocialNetworks']);
$translations['Referrers_visitorsFromDirectEntry'] = Piwik::translate('Referrers_VisitorsFromDirectEntry');
$translations['Referrers_visitorsFromDirectEntry_percent'] = Piwik::translate('Referrers_PercentOfX', $translations['Referrers_visitorsFromDirectEntry']);
$translations['Referrers_visitorsFromWebsites'] = Piwik::translate('Referrers_VisitorsFromWebsites');
$translations['Referrers_visitorsFromWebsites_percent'] = Piwik::translate('Referrers_PercentOfX', $translations['Referrers_visitorsFromWebsites']);
$translations['Referrers_visitorsFromCampaigns'] = Piwik::translate('Referrers_VisitorsFromCampaigns');
$translations['Referrers_visitorsFromCampaigns_percent'] = Piwik::translate('Referrers_PercentOfX', $translations['Referrers_visitorsFromCampaigns']);
$translations[Archiver::METRIC_DISTINCT_SEARCH_ENGINE_RECORD_NAME] = ucfirst(Piwik::translate('Referrers_DistinctSearchEngines'));
$translations[Archiver::METRIC_DISTINCT_SOCIAL_NETWORK_RECORD_NAME] = ucfirst(Piwik::translate('Referrers_DistinctSocialNetworks'));
$translations[Archiver::METRIC_DISTINCT_WEBSITE_RECORD_NAME] = ucfirst(Piwik::translate('Referrers_DistinctWebsites'));
$translations[Archiver::METRIC_DISTINCT_KEYWORD_RECORD_NAME] = ucfirst(Piwik::translate('Referrers_DistinctKeywords'));
$translations[Archiver::METRIC_DISTINCT_CAMPAIGN_RECORD_NAME] = ucfirst(Piwik::translate('Referrers_DistinctCampaigns'));
}
public function getPagesComparisonsDisabledFor(&$pages)
{
$pages[] = 'Referrers_Referrers.Referrers_URLCampaignBuilder';
}
public function getStylesheetFiles(&$stylesheets)
{
$stylesheets[] = 'plugins/Referrers/angularjs/campaign-builder/campaign-builder.directive.less';
}
public function getClientSideTranslationKeys(&$translationKeys)
{
$translationKeys[] = 'General_Required2';
$translationKeys[] = 'General_Clear';
$translationKeys[] = 'Actions_ColumnPageURL';
$translationKeys[] = 'CoreAdminHome_JSTracking_CampaignNameParam';
$translationKeys[] = 'CoreAdminHome_JSTracking_CampaignKwdParam';
$translationKeys[] = 'Referrers_CampaignSource';
$translationKeys[] = 'Referrers_CampaignSourceHelp';
$translationKeys[] = 'Referrers_CampaignContent';
$translationKeys[] = 'Referrers_CampaignContentHelp';
$translationKeys[] = 'Referrers_CampaignMedium';
$translationKeys[] = 'Referrers_CampaignMediumHelp';
$translationKeys[] = 'Referrers_CampaignPageUrlHelp';
$translationKeys[] = 'Referrers_CampaignNameHelp';
$translationKeys[] = 'Referrers_CampaignKeywordHelp';
$translationKeys[] = 'Referrers_URLCampaignBuilderResult';
$translationKeys[] = 'Referrers_GenerateUrl';
$translationKeys[] = 'Goals_Optional';
}
public function getJsFiles(&$jsFiles)
{
$jsFiles[] = 'plugins/Referrers/angularjs/campaign-builder/campaign-builder.controller.js';
$jsFiles[] = 'plugins/Referrers/angularjs/campaign-builder/campaign-builder.directive.js';
}
public function setTrackerCacheGeneral(&$cacheContent)
{
$siteUrls = new SiteUrls();
$urls = $siteUrls->getAllCachedSiteUrls();
return $cacheContent['allUrlsByHostAndIdSite'] = $siteUrls->groupUrlsByHost($urls);
}
public function renameDeprecatedModuleAndAction(&$module, &$action)
{
if($module == 'Referers') {
$module = 'Referrers';
}
}
public function addReportToInsightsOverview(&$reports)
{
$reports['Referrers_getWebsites'] = array();
$reports['Referrers_getCampaigns'] = array();
$reports['Referrers_getSocials'] = array();
$reports['Referrers_getSearchEngines'] = array();
}
/**
* DataTable filter callback that returns the HTML prefix for a label in the
* 'getAll' report based on the row's referrer type.
*
* @param int $referrerType The referrer type.
* @return string
*/
public function setGetAllHtmlPrefix($referrerType)
{
// get singular label for referrer type
$indexTranslation = '';
switch ($referrerType) {
case Common::REFERRER_TYPE_DIRECT_ENTRY:
$indexTranslation = 'Referrers_DirectEntry';
break;
case Common::REFERRER_TYPE_SEARCH_ENGINE:
$indexTranslation = 'General_ColumnKeyword';
break;
case Common::REFERRER_TYPE_SOCIAL_NETWORK:
$indexTranslation = 'Referrers_ColumnSocial';
break;
case Common::REFERRER_TYPE_WEBSITE:
$indexTranslation = 'Referrers_ColumnWebsite';
break;
case Common::REFERRER_TYPE_CAMPAIGN:
$indexTranslation = 'Referrers_ColumnCampaign';
break;
default:
// case of newsletter, partners, before Piwik 0.2.25
$indexTranslation = 'General_Others';
break;
}
$label = strtolower(Piwik::translate($indexTranslation));
// return html that displays it as grey & italic
return '<span class="datatable-label-category">(' . $label . ')</span>';
}
}
|