-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #679 from EPNW/matomo-tag-extensions
Several new options for the Matomo Configuration
- Loading branch information
Showing
8 changed files
with
689 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
/** | ||
* Matomo - 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\TagManager\Template\Variable; | ||
|
||
use Piwik\Piwik; | ||
use Piwik\Settings\FieldConfig; | ||
use Piwik\Validators\NotEmpty; | ||
|
||
class CustomRequestProcessingVariable extends BaseVariable | ||
{ | ||
const ID = 'CustomRequestProcessing'; | ||
|
||
public function getId() | ||
{ | ||
return self::ID; | ||
} | ||
|
||
public function getCategory() | ||
{ | ||
return self::CATEGORY_OTHERS; | ||
} | ||
|
||
public function isCustomTemplate() | ||
{ | ||
return true; | ||
} | ||
|
||
public function getParameters() | ||
{ | ||
return array( | ||
$this->makeSetting('jsFunction', "function(request){ return request; }", FieldConfig::TYPE_STRING, function (FieldConfig $field) { | ||
$field->title = Piwik::translate('TagManager_CustomRequestProcessingVariableJsFunctionTitle'); | ||
$field->description = Piwik::translate('TagManager_CustomRequestProcessingVariableJsFunctionDescription'); | ||
$field->uiControl = FieldConfig::UI_CONTROL_TEXTAREA; | ||
$field->validators[] = new NotEmpty(); | ||
$field->validate = function ($value) { | ||
$value = trim($value); | ||
if (strpos($value, 'function(request){') !== 0) { | ||
throw new \Exception('The value needs to start with "function(request){"'); | ||
} | ||
}; | ||
$field->transform = function ($value) { | ||
return trim($value); | ||
}; | ||
}), | ||
); | ||
} | ||
|
||
public function loadTemplate($context, $entity) | ||
{ | ||
if (!empty($entity['parameters']['jsFunction'])) { | ||
$function = rtrim(trim($entity['parameters']['jsFunction']), ';'); | ||
|
||
return '(function () { return function (parameters, TagManager) { this.get = function(){ return ' . $function . '; } ; } })();'; | ||
} | ||
} | ||
|
||
public function hasAdvancedSettings() | ||
{ | ||
return false; | ||
} | ||
} |
Oops, something went wrong.