From 1a9df8bc6861cb7a13c94f885357ca8ef5141546 Mon Sep 17 00:00:00 2001 From: Bernhard Rusch Date: Mon, 18 Apr 2016 12:00:30 +0200 Subject: [PATCH 1/4] added more functionalities: custom piwik.js, piwik.php and _paq JS variable --- API.php | 2 +- Settings.php | 52 ++++++++++++++++ TrackingCodeCustomizer.php | 119 +++++++++++++++++++++++++++++++++---- lang/en.json | 10 +++- 4 files changed, 168 insertions(+), 15 deletions(-) diff --git a/API.php b/API.php index 057f6cf..3206171 100644 --- a/API.php +++ b/API.php @@ -11,7 +11,7 @@ public function getSettings() { $outParams = array(); - $params = array("idSite","piwikUrl","options","optionsBeforeTrackerUrl","httpsPiwikUrl","protocol"); + $params = array("idSite","piwikUrl","options","optionsBeforeTrackerUrl","httpsPiwikUrl","protocol","piwikJs", "piwikPhp","paqVariable","removePiwikBranding"); $settings = new Settings(self::$plugin_name); diff --git a/Settings.php b/Settings.php index fece049..0a8cc83 100644 --- a/Settings.php +++ b/Settings.php @@ -14,6 +14,10 @@ class Settings extends \Piwik\Plugin\Settings public $optionsBeforeTrackerUrl; public $httpsPiwikUrl; public $protocol; + public $piwikJs; + public $piwikPhp; + public $paqVariable; + public $removePiwikBranding; protected function init() { @@ -77,6 +81,54 @@ protected function init() $this->httpsPiwikUrl->inlineHelp = 'secure-tracker.example.com/piwik use hostname+basepath only (omit protocol and trailing slash)'; $this->addSetting($this->httpsPiwikUrl); + + + $this->piwikJs = new SystemSetting('piwikJs', $this->t('piwikJsSettingTitle')); + $this->piwikJs->type = static::TYPE_STRING; + $this->piwikJs->uiControlType = static::CONTROL_TEXT; + $this->piwikJs->uiControlAttributes = $default_textbox_size; + $this->piwikJs->description = $this->t('piwikJsSettingDescription'); + $this->piwikJs->readableByCurrentUser = true; + $this->piwikJs->defaultValue = ""; + $this->piwikJs->inlineHelp = 'alternative name for piwik.js in Javascript tracking code'; + + $this->addSetting($this->piwikJs); + + + $this->piwikPhp = new SystemSetting('piwikPhp', $this->t('piwikPhpSettingTitle')); + $this->piwikPhp->type = static::TYPE_STRING; + $this->piwikPhp->uiControlType = static::CONTROL_TEXT; + $this->piwikPhp->uiControlAttributes = $default_textbox_size; + $this->piwikPhp->description = $this->t('piwikPhpSettingDescription'); + $this->piwikPhp->readableByCurrentUser = true; + $this->piwikPhp->defaultValue = ""; + $this->piwikPhp->inlineHelp = 'alternative name for piwik.php in Javascript tracking code'; + + $this->addSetting($this->piwikPhp); + + + $this->paqVariable = new SystemSetting('paqVariable', $this->t('paqVariableSettingTitle')); + $this->paqVariable->type = static::TYPE_STRING; + $this->paqVariable->uiControlType = static::CONTROL_TEXT; + $this->paqVariable->uiControlAttributes = $default_textbox_size; + $this->paqVariable->description = $this->t('paqVariableSettingDescription'); + $this->paqVariable->readableByCurrentUser = true; + $this->paqVariable->defaultValue = ""; + $this->paqVariable->inlineHelp = 'alternative name for _paq'; + + $this->addSetting($this->paqVariable); + + + $this->removePiwikBranding = new SystemSetting('removePiwikBranding', $this->t('removePiwikBrandingSettingTitle')); + $this->removePiwikBranding->type = static::TYPE_BOOL; + $this->removePiwikBranding->uiControlType = static::CONTROL_CHECKBOX; + $this->removePiwikBranding->description = $this->t('removePiwikBrandingSettingDescription'); + $this->removePiwikBranding->readableByCurrentUser = true; + $this->removePiwikBranding->defaultValue = ""; + $this->removePiwikBranding->inlineHelp = 'Remove Piwik branding in comments'; + + $this->addSetting($this->removePiwikBranding); + $this->options = new SystemSetting('options', $this->t('optionsSettingTitle')); $this->options->type = static::TYPE_STRING; diff --git a/TrackingCodeCustomizer.php b/TrackingCodeCustomizer.php index bb859f5..258e34b 100644 --- a/TrackingCodeCustomizer.php +++ b/TrackingCodeCustomizer.php @@ -37,7 +37,10 @@ class TrackingCodeCustomizer extends \Piwik\Plugin { private static $hooks = array( - 'Piwik.getJavascriptCode' => 'applyTrackingCodeCustomizations' + 'Piwik.getJavascriptCode' => 'applyTrackingCodeCustomizations', + 'Controller.CoreAdminHome.setPluginSettings.end' => 'rewriteJavascriptFiles', + 'API.SitesManager.getJavascriptTag.end' => 'rewriteJavascriptTag', + 'CoreUpdater.update.end' => 'afterUpdate' ); //2.15 includes a new function for registering hooks. 2.15 wi @@ -74,29 +77,119 @@ public function getListHooksRegistered() public function applyTrackingCodeCustomizations(&$sysparams,$parameters){ $originalSysparams = $sysparams; + $storedSettings = $this->getSettings(); - $settings = API::getInstance(); - - $storedSettings = $settings->getSettings(); - - if(array_key_exists("options", $storedSettings)) - $storedSettings["options"] .= $sysparams["options"]; + if(array_key_exists("options", $storedSettings)) { + $storedSettings["options"] .= $sysparams["options"]; + } - if(array_key_exists("optionsBeforeTrackerUrl", $storedSettings)) - $storedSettings["optionsBeforeTrackerUrl"] .=$sysparams["optionsBeforeTrackerUrl"]; - - $sysparams = array_merge($sysparams,$storedSettings); + if(array_key_exists("optionsBeforeTrackerUrl", $storedSettings)) { + $storedSettings["optionsBeforeTrackerUrl"] .= $sysparams["optionsBeforeTrackerUrl"]; + } + + $sysparams = array_merge($sysparams, $storedSettings); foreach($sysparams as $key => $value){ - $sysparams[$key] = $this->replaceTokens($value,$originalSysparams,$sysparams); } } - + + /** + * @param $subject + * @param $originalSysparams + * @param $sysparams + * @return mixed + */ private function replaceTokens($subject,$originalSysparams,$sysparams){ $output = str_replace(array_map(function($item){return '{$original_'.$item.'}';},array_keys($originalSysparams)),array_values($originalSysparams),$subject); $output = str_replace(array_map(function($item){return '{$'.$item.'}';},array_keys($sysparams)),array_values($sysparams),$output); return $output; } + + /** + * @return array + */ + protected function getSettings() { + $settings = API::getInstance(); + $storedSettings = $settings->getSettings(); + return $storedSettings; + } + + /** + * @return string + */ + protected function getTrackingCodeFile() { + return $trackingCodeFile = PIWIK_INCLUDE_PATH . "/piwik.js"; + } + + /** + * + */ + public function afterUpdate() { + + // cleanup old original file + $oldOriginalCodeFile = $this->getTrackingCodeFile() . ".original"; + if(file_exists($oldOriginalCodeFile)) { + unlink($oldOriginalCodeFile); + } + + $this->rewriteJavascriptFiles(); + } + + /** + * + */ + public function rewriteJavascriptFiles() { + $trackingCodeFile = $this->getTrackingCodeFile(); + $trackingCodeFileOriginal = $trackingCodeFile . ".original"; + + if(!file_exists($trackingCodeFileOriginal)) { + copy($trackingCodeFile, $trackingCodeFileOriginal); + } + + $trackingCode = file_get_contents($trackingCodeFileOriginal); + + $settings = $this->getSettings(); + + if(array_key_exists("paqVariable", $settings)) { + $trackingCode = str_replace("_paq", $settings["paqVariable"], $trackingCode); + } + + if(array_key_exists("piwikJs", $settings)) { + $trackingCode = str_replace("piwik.js", $settings["piwikJs"], $trackingCode); + } + + if(array_key_exists("piwikPhp", $settings)) { + $trackingCode = str_replace("piwik.php", $settings["piwikPhp"], $trackingCode); + } + + file_put_contents($trackingCodeFile, $trackingCode); + } + + /** + * @param $result + * @param $parameters + */ + public function rewriteJavascriptTag(&$result, $parameters) { + + $settings = $this->getSettings(); + + if(array_key_exists("paqVariable", $settings)) { + $result = str_replace("_paq", $settings["paqVariable"], $result); + } + + if(array_key_exists("piwikJs", $settings)) { + $result = str_replace("piwik.js", $settings["piwikJs"], $result); + } + + if(array_key_exists("piwikPhp", $settings)) { + $result = str_replace("piwik.php", $settings["piwikPhp"], $result); + } + + if(array_key_exists("removePiwikBranding", $settings)) { + $result = preg_replace('//', '', $result); + $result = str_replace(" Piwik ", " Tracking ", $result); + } + } } diff --git a/lang/en.json b/lang/en.json index 274d144..4efbf7e 100644 --- a/lang/en.json +++ b/lang/en.json @@ -12,6 +12,14 @@ "optionsSettingTitle":"options", "optionsSettingDescription":"A string of JavaScript code that customizes the JavaScript tracker (after _paq = _paq || [] and before trackPageView).", "optionsBeforeTrackerUrlSettingTitle":"optionsBeforeTrackerUrl", - "optionsBeforeTrackerUrlSettingDescription":"A string of Javascript code that customizes the JavaScript tracker inside of anonymous function before adding setTrackerUrl into paq." + "optionsBeforeTrackerUrlSettingDescription":"A string of Javascript code that customizes the JavaScript tracker inside of anonymous function before adding setTrackerUrl into paq.", + "piwikJsSettingTitle": "piwik.js Filename", + "piwikJsSettingDescription": "Let's you customize the piwik.js Filename, don't forget to create a rewrite accordingly.", + "piwikPhpSettingTitle": "piwik.php Filename", + "piwikPhpSettingDescription": "Let's you customize the piwik.php Filename, don't forget to create a rewrite accordingly.", + "paqVariableSettingTitle": "Name for _paq in Javascript tracking code", + "paqVariableSettingDescription": "Let's you customize the _paq JS Variable in your tracking code", + "removePiwikBrandingSettingTitle": "Remove PIWIK branking in tracking code", + "removePiwikBrandingSettingDescription": "Removed the name PIWIK out of the comments in the code" } } \ No newline at end of file From 5f22fbad8250159d24aaac34baad312fb412e132 Mon Sep 17 00:00:00 2001 From: Bernhard Rusch Date: Tue, 26 Apr 2016 09:14:37 +0200 Subject: [PATCH 2/4] various optimizations --- Settings.php | 75 ++++++++++++++++++-------------------- TrackingCodeCustomizer.php | 4 +- lang/en.json | 46 ++++++++++++++--------- 3 files changed, 67 insertions(+), 58 deletions(-) diff --git a/Settings.php b/Settings.php index 0a8cc83..c4e6419 100644 --- a/Settings.php +++ b/Settings.php @@ -18,7 +18,8 @@ class Settings extends \Piwik\Plugin\Settings public $piwikPhp; public $paqVariable; public $removePiwikBranding; - + public $infoTextWritePermissions; + protected function init() { $this->setIntroduction($this->t('PluginDescription')); @@ -27,13 +28,12 @@ protected function init() $this->idSite = new SystemSetting('idSite', $this->t('idSiteSettingTitle')); + $this->idSite->inlineHelp = $this->t('idSiteSettingHelp'); $this->idSite->type = static::TYPE_STRING; $this->idSite->uiControlType = static::CONTROL_TEXT; $this->idSite->uiControlAttributes = array("size" => "6", "maxlenth" => "8"); - $this->idSite->description = $this->t('idSiteSettingDescription'); $this->idSite->readableByCurrentUser = true; $this->idSite->defaultValue = ""; - $this->idSite->inlineHelp = 'Probably not useful in most scenarios. The idSite option is included for completeness.'; $this->idSite->validate = function ($value, $setting) { if ($value != "" && preg_match("/^[0-9]+$/",$value) !== 1) { @@ -44,13 +44,12 @@ protected function init() $this->addSetting($this->idSite); $this->protocol = new SystemSetting('protocol', $this->t('protocolSettingTitle')); + $this->protocol->inlineHelp = $this->t('protocolSettingHelp'); $this->protocol->type = static::TYPE_STRING; $this->protocol->uiControlType = static::CONTROL_TEXT; $this->protocol->uiControlAttributes = array("size" => "10", "maxlenth" => "8"); - $this->protocol->description = $this->t('protocolSettingDescription'); $this->protocol->readableByCurrentUser = true; $this->protocol->defaultValue = ""; - $this->protocol->inlineHelp = 'http(s)://'; $this->protocol->validate = function ($value, $setting) { if ($value != "" && !($value == "http://" || $value == "https://")) { @@ -61,94 +60,92 @@ protected function init() $this->addSetting($this->protocol); $this->piwikUrl = new SystemSetting('piwikUrl', $this->t('piwikUrlSettingTitle')); + $this->piwikUrl->inlineHelp = $this->t('piwikUrlSettingHelp'); $this->piwikUrl->type = static::TYPE_STRING; $this->piwikUrl->uiControlType = static::CONTROL_TEXT; $this->piwikUrl->uiControlAttributes = $default_textbox_size; - $this->piwikUrl->description = $this->t('piwikUrlSettingDescription'); $this->piwikUrl->readableByCurrentUser = true; $this->piwikUrl->defaultValue = ""; - $this->piwikUrl->inlineHelp = 'tracker.example.com/piwik use hostname+basepath only (omit protocol and trailing slash)'; $this->addSetting($this->piwikUrl); $this->httpsPiwikUrl = new SystemSetting('httpsPiwikUrl', $this->t('httpsPiwikUrlSettingTitle')); + $this->httpsPiwikUrl->inlineHelp = $this->t('httpsPiwikUrlSettingHelp'); $this->httpsPiwikUrl->type = static::TYPE_STRING; $this->httpsPiwikUrl->uiControlType = static::CONTROL_TEXT; $this->httpsPiwikUrl->uiControlAttributes = $default_textbox_size; - $this->httpsPiwikUrl->description = $this->t('httpsPiwikUrlSettingDescription'); $this->httpsPiwikUrl->readableByCurrentUser = true; $this->httpsPiwikUrl->defaultValue = ""; - $this->httpsPiwikUrl->inlineHelp = 'secure-tracker.example.com/piwik use hostname+basepath only (omit protocol and trailing slash)'; - + $this->addSetting($this->httpsPiwikUrl); + + $this->options = new SystemSetting('options', $this->t('optionsSettingTitle')); + $this->options->type = static::TYPE_STRING; + $this->options->uiControlType = static::CONTROL_TEXTAREA; + $this->options->description = $this->t('optionsSettingDescription'); + $this->options->readableByCurrentUser = true; + $this->options->defaultValue = ""; + $this->options->inlineHelp = '{$original_paramname} and {$paramname} tokens are available for referencing values.'; + + $this->addSetting($this->options); + + $this->optionsBeforeTrackerUrl = new SystemSetting('optionsBeforeTrackerUrl', $this->t('optionsBeforeTrackerUrlSettingTitle')); + $this->optionsBeforeTrackerUrl->type = static::TYPE_STRING; + $this->optionsBeforeTrackerUrl->uiControlType = static::CONTROL_TEXTAREA; + $this->optionsBeforeTrackerUrl->description = $this->t('optionsBeforeTrackerUrlSettingDescription'); + $this->optionsBeforeTrackerUrl->readableByCurrentUser = true; + $this->optionsBeforeTrackerUrl->defaultValue = ""; + $this->optionsBeforeTrackerUrl->inlineHelp = '{$original_paramname} and {$paramname} tokens are available for referencing values.'; + + $this->addSetting($this->optionsBeforeTrackerUrl); + + $this->piwikJs = new SystemSetting('piwikJs', $this->t('piwikJsSettingTitle')); + if(!is_writeable(PIWIK_INCLUDE_PATH . "/piwik.js")) { + $this->piwikJs->introduction = $this->t("writePermissionInfoText"); + } + $this->piwikJs->inlineHelp = $this->t("piwikJsSettingHelp"); $this->piwikJs->type = static::TYPE_STRING; $this->piwikJs->uiControlType = static::CONTROL_TEXT; $this->piwikJs->uiControlAttributes = $default_textbox_size; - $this->piwikJs->description = $this->t('piwikJsSettingDescription'); $this->piwikJs->readableByCurrentUser = true; $this->piwikJs->defaultValue = ""; - $this->piwikJs->inlineHelp = 'alternative name for piwik.js in Javascript tracking code'; $this->addSetting($this->piwikJs); $this->piwikPhp = new SystemSetting('piwikPhp', $this->t('piwikPhpSettingTitle')); + $this->piwikPhp->inlineHelp = $this->t('piwikPhpSettingHelp'); $this->piwikPhp->type = static::TYPE_STRING; $this->piwikPhp->uiControlType = static::CONTROL_TEXT; $this->piwikPhp->uiControlAttributes = $default_textbox_size; - $this->piwikPhp->description = $this->t('piwikPhpSettingDescription'); $this->piwikPhp->readableByCurrentUser = true; $this->piwikPhp->defaultValue = ""; - $this->piwikPhp->inlineHelp = 'alternative name for piwik.php in Javascript tracking code'; $this->addSetting($this->piwikPhp); $this->paqVariable = new SystemSetting('paqVariable', $this->t('paqVariableSettingTitle')); + $this->paqVariable->inlineHelp = $this->t('paqVariableSettingHelp'); $this->paqVariable->type = static::TYPE_STRING; $this->paqVariable->uiControlType = static::CONTROL_TEXT; $this->paqVariable->uiControlAttributes = $default_textbox_size; - $this->paqVariable->description = $this->t('paqVariableSettingDescription'); $this->paqVariable->readableByCurrentUser = true; $this->paqVariable->defaultValue = ""; - $this->paqVariable->inlineHelp = 'alternative name for _paq'; $this->addSetting($this->paqVariable); $this->removePiwikBranding = new SystemSetting('removePiwikBranding', $this->t('removePiwikBrandingSettingTitle')); + $this->removePiwikBranding->inlineHelp = $this->t('removePiwikBrandingSettingHelp'); $this->removePiwikBranding->type = static::TYPE_BOOL; $this->removePiwikBranding->uiControlType = static::CONTROL_CHECKBOX; - $this->removePiwikBranding->description = $this->t('removePiwikBrandingSettingDescription'); $this->removePiwikBranding->readableByCurrentUser = true; $this->removePiwikBranding->defaultValue = ""; - $this->removePiwikBranding->inlineHelp = 'Remove Piwik branding in comments'; $this->addSetting($this->removePiwikBranding); - - - $this->options = new SystemSetting('options', $this->t('optionsSettingTitle')); - $this->options->type = static::TYPE_STRING; - $this->options->uiControlType = static::CONTROL_TEXTAREA; - $this->options->description = $this->t('optionsSettingDescription'); - $this->options->readableByCurrentUser = true; - $this->options->defaultValue = ""; - $this->options->inlineHelp = '{$original_paramname} and {$paramname} tokens are available for referencing values.'; - - $this->addSetting($this->options); - - $this->optionsBeforeTrackerUrl = new SystemSetting('optionsBeforeTrackerUrl', $this->t('optionsBeforeTrackerUrlSettingTitle')); - $this->optionsBeforeTrackerUrl->type = static::TYPE_STRING; - $this->optionsBeforeTrackerUrl->uiControlType = static::CONTROL_TEXTAREA; - $this->optionsBeforeTrackerUrl->description = $this->t('optionsBeforeTrackerUrlSettingDescription'); - $this->optionsBeforeTrackerUrl->readableByCurrentUser = true; - $this->optionsBeforeTrackerUrl->defaultValue = ""; - $this->optionsBeforeTrackerUrl->inlineHelp = '{$original_paramname} and {$paramname} tokens are available for referencing values.'; - - $this->addSetting($this->optionsBeforeTrackerUrl); } private function t($key) diff --git a/TrackingCodeCustomizer.php b/TrackingCodeCustomizer.php index 258e34b..566cd46 100644 --- a/TrackingCodeCustomizer.php +++ b/TrackingCodeCustomizer.php @@ -40,6 +40,7 @@ class TrackingCodeCustomizer extends \Piwik\Plugin 'Piwik.getJavascriptCode' => 'applyTrackingCodeCustomizations', 'Controller.CoreAdminHome.setPluginSettings.end' => 'rewriteJavascriptFiles', 'API.SitesManager.getJavascriptTag.end' => 'rewriteJavascriptTag', + 'Controller.SitesManager.siteWithoutData.end' => 'rewriteJavascriptTag', 'CoreUpdater.update.end' => 'afterUpdate' ); @@ -188,8 +189,7 @@ public function rewriteJavascriptTag(&$result, $parameters) { } if(array_key_exists("removePiwikBranding", $settings)) { - $result = preg_replace('//', '', $result); - $result = str_replace(" Piwik ", " Tracking ", $result); + $result = preg_replace('/<\!\-\- .* \-\->/', '', $result); } } } diff --git a/lang/en.json b/lang/en.json index 4efbf7e..3457e49 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1,25 +1,37 @@ { "TrackingCodeCustomizer": { "PluginDescription":"The provided values will replace the defaults in the generated tracking code (leave blank to use defaults). Viewing https://github.com/piwik/piwik/blob/master/core/Tracker/TrackerCodeGenerator.php is recommended to deconstruct how the tracking code is built.", - "idSiteSettingTitle":"idSite", - "idSiteSettingDescription":"The siteId that will be included in the tracking code.", - "protocolSettingTitle":"protocol", - "protocolSettingDescription":"Piwik url protocol.", - "piwikUrlSettingTitle":"piwikUrl", - "piwikUrlSettingDescription":"The tracker URL to use.", - "httpsPiwikUrlSettingTitle":"httpsPiwikUrl", - "httpsPiwikUrlSettingDescription":"Set if the HTTPS domain is different from the normal domain.", - "optionsSettingTitle":"options", - "optionsSettingDescription":"A string of JavaScript code that customizes the JavaScript tracker (after _paq = _paq || [] and before trackPageView).", - "optionsBeforeTrackerUrlSettingTitle":"optionsBeforeTrackerUrl", - "optionsBeforeTrackerUrlSettingDescription":"A string of Javascript code that customizes the JavaScript tracker inside of anonymous function before adding setTrackerUrl into paq.", + + "idSiteSettingTitle":"The siteId that will be included in the tracking code.", + "idSiteSettingHelp": "Probably not useful in most scenarios. The idSite option is included for completeness.", + + "protocolSettingTitle":"Piwik default URL protocol", + "protocolSettingHelp":"eg. http(s):// - allows to set the default protocol instead of the protocol relative URL", + + "piwikUrlSettingTitle":"The tracker URL to use.", + "piwikUrlSettingHelp":"eg. 'tracker.example.com/piwik' use hostname + basepath only (omit protocol and trailing slash)", + + "httpsPiwikUrlSettingTitle":"HTTPS tracker URL (if different from normal domain)", + "httpsPiwikUrlSettingHelp":"Set if the HTTPS domain is different from the normal domain. Example: 'tracker.example.com/piwik' use hostname + basepath only (omit protocol and trailing slash)", + "piwikJsSettingTitle": "piwik.js Filename", - "piwikJsSettingDescription": "Let's you customize the piwik.js Filename, don't forget to create a rewrite accordingly.", + "piwikJsSettingHelp": "Let's you customize the piwik.js Filename. This is useful to avoid detections by AdBlockers. Don't forget to create a rewrite rrule accordingly in your web-server configuration: RewriteRule \"^/p/p.(js|php)$\" \"/piwik/piwik.$1\" [PT,L]", + "piwikPhpSettingTitle": "piwik.php Filename", - "piwikPhpSettingDescription": "Let's you customize the piwik.php Filename, don't forget to create a rewrite accordingly.", + "piwikPhpSettingHelp": "Let's you customize the piwik.php Filename. This is useful to avoid detections by AdBlockers. Don't forget to create a rewrite rrule accordingly in your web-server configuration: RewriteRule \"^/p/p.(js|php)$\" \"/piwik/piwik.$1\" [PT,L]", + "paqVariableSettingTitle": "Name for _paq in Javascript tracking code", - "paqVariableSettingDescription": "Let's you customize the _paq JS Variable in your tracking code", - "removePiwikBrandingSettingTitle": "Remove PIWIK branking in tracking code", - "removePiwikBrandingSettingDescription": "Removed the name PIWIK out of the comments in the code" + "paqVariableSettingHelp": "Let's you customize the _paq JS Variable in your tracking code. This can be useful to avoid issues with multiple Piwik tracking codes on the same page.", + + "removePiwikBrandingSettingTitle": "Remove Piwik branding comments in tracking code", + "removePiwikBrandingSettingHelp": "Remove the comments containing 'Piwik' out of the standard tracking code", + + "optionsSettingTitle":"Code options", + "optionsSettingDescription":"A string of JavaScript code that customizes the JavaScript tracker (after _paq = _paq || [] and before trackPageView).", + + "optionsBeforeTrackerUrlSettingTitle":"Code options before tracker URL", + "optionsBeforeTrackerUrlSettingDescription":"A string of Javascript code that customizes the JavaScript tracker inside of anonymous function before adding setTrackerUrl into paq.", + + "writePermissionInfoText": "WARNING: %PIWIK_INCLUDE_PATH%/piwik.js is not writeable by the webserver. If you'd like to use the following settings, please change the permissions of the file or apply the changes manually." } } \ No newline at end of file From f9dd1cec3f51e978b9a8b8d4f57b02ba1e66ce88 Mon Sep 17 00:00:00 2001 From: Bernhard Rusch Date: Tue, 26 Apr 2016 09:20:10 +0200 Subject: [PATCH 3/4] various optimizations --- lang/en.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/en.json b/lang/en.json index 3457e49..1a425b6 100644 --- a/lang/en.json +++ b/lang/en.json @@ -15,10 +15,10 @@ "httpsPiwikUrlSettingHelp":"Set if the HTTPS domain is different from the normal domain. Example: 'tracker.example.com/piwik' use hostname + basepath only (omit protocol and trailing slash)", "piwikJsSettingTitle": "piwik.js Filename", - "piwikJsSettingHelp": "Let's you customize the piwik.js Filename. This is useful to avoid detections by AdBlockers. Don't forget to create a rewrite rrule accordingly in your web-server configuration: RewriteRule \"^/p/p.(js|php)$\" \"/piwik/piwik.$1\" [PT,L]", + "piwikJsSettingHelp": "Let's you customize the piwik.js Filename. This is useful to avoid detections by AdBlockers. Don't forget to create a rewrite rule accordingly in your web-server configuration: RewriteRule \"^/p/p.(js|php)$\" \"/piwik/piwik.$1\" [PT,L]", "piwikPhpSettingTitle": "piwik.php Filename", - "piwikPhpSettingHelp": "Let's you customize the piwik.php Filename. This is useful to avoid detections by AdBlockers. Don't forget to create a rewrite rrule accordingly in your web-server configuration: RewriteRule \"^/p/p.(js|php)$\" \"/piwik/piwik.$1\" [PT,L]", + "piwikPhpSettingHelp": "Let's you customize the piwik.php Filename. This is useful to avoid detections by AdBlockers. Don't forget to create a rewrite rule accordingly in your web-server configuration: RewriteRule \"^/p/p.(js|php)$\" \"/piwik/piwik.$1\" [PT,L] Please note that changing the trackers filename needs to be addressed when using the log analyzer (use --replay-tracking-expected-tracker-file=yourfilename.php)", "paqVariableSettingTitle": "Name for _paq in Javascript tracking code", "paqVariableSettingHelp": "Let's you customize the _paq JS Variable in your tracking code. This can be useful to avoid issues with multiple Piwik tracking codes on the same page.", From 55886ba00a07557238de66dbe5409d2a4c4867b5 Mon Sep 17 00:00:00 2001 From: Bernhard Rusch Date: Tue, 26 Apr 2016 09:21:56 +0200 Subject: [PATCH 4/4] various optimizations --- TrackingCodeCustomizer.php | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/TrackingCodeCustomizer.php b/TrackingCodeCustomizer.php index 566cd46..0ce510c 100644 --- a/TrackingCodeCustomizer.php +++ b/TrackingCodeCustomizer.php @@ -143,29 +143,32 @@ public function afterUpdate() { */ public function rewriteJavascriptFiles() { $trackingCodeFile = $this->getTrackingCodeFile(); - $trackingCodeFileOriginal = $trackingCodeFile . ".original"; - if(!file_exists($trackingCodeFileOriginal)) { - copy($trackingCodeFile, $trackingCodeFileOriginal); - } + if(is_writeable($trackingCodeFile)) { + $trackingCodeFileOriginal = $trackingCodeFile . ".original"; - $trackingCode = file_get_contents($trackingCodeFileOriginal); + if (!file_exists($trackingCodeFileOriginal)) { + copy($trackingCodeFile, $trackingCodeFileOriginal); + } - $settings = $this->getSettings(); + $trackingCode = file_get_contents($trackingCodeFileOriginal); - if(array_key_exists("paqVariable", $settings)) { - $trackingCode = str_replace("_paq", $settings["paqVariable"], $trackingCode); - } + $settings = $this->getSettings(); - if(array_key_exists("piwikJs", $settings)) { - $trackingCode = str_replace("piwik.js", $settings["piwikJs"], $trackingCode); - } + if (array_key_exists("paqVariable", $settings)) { + $trackingCode = str_replace("_paq", $settings["paqVariable"], $trackingCode); + } - if(array_key_exists("piwikPhp", $settings)) { - $trackingCode = str_replace("piwik.php", $settings["piwikPhp"], $trackingCode); - } + if (array_key_exists("piwikJs", $settings)) { + $trackingCode = str_replace("piwik.js", $settings["piwikJs"], $trackingCode); + } - file_put_contents($trackingCodeFile, $trackingCode); + if (array_key_exists("piwikPhp", $settings)) { + $trackingCode = str_replace("piwik.php", $settings["piwikPhp"], $trackingCode); + } + + file_put_contents($trackingCodeFile, $trackingCode); + } } /**