Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Ads Tag #50

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions Template/Tag/GoogleAds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
(function () {
return function (parameters, TagManager) {
this.fire = function () {
var imageUrl = parameters.get('conversionID');
if (!imageUrl) {
return;
}
TagManager.dom.loadScriptUrl('https://www.googleadservices.com/pagead/conversion_async.js', {
onload: function () {
var conversionID = parameters.get('conversionID');
var configObject = {
google_conversion_id: conversionID,
google_conversion_format: parameters.get('conversionFormat'),
google_remarketing_only: false
};
var conversionCurrency = parameters.get("conversionCurrency");
if (conversionCurrency) {
configObject.google_conversion_currency = conversionCurrency;
}
var conversionValue = parameters.get("conversionValue");
if (conversionValue) {
configObject.google_conversion_value = conversionValue;
}
var conversionLanguage = parameters.get("conversionLanguage");
if (conversionLanguage) {
configObject.google_conversion_language = conversionLanguage;
}
var conversionColor = parameters.get("conversionColor");
if (conversionColor) {
configObject.google_conversion_color = conversionColor;
}
var rawTagParameters = parameters.get("tagParameters");
if (rawTagParameters) {
var tagParameters = {};
for (var i = 0; i < rawTagParameters.length - 1; i++) {
tagParameters[rawTagParameters[i]["parameter"]] = rawTagParameters[i]["value"]
}
console.warn(tagParameters);
window.google_tag_params = tagParameters
}

configObject.google_conversion_label = conversionID + '/' + parameters.get('conversionLabel');
window.google_trackConversion(configObject)
}
});
};
};
})();
81 changes: 81 additions & 0 deletions Template/Tag/GoogleAds.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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\Tag;

use Piwik\Settings\FieldConfig;
use Piwik\Plugins\TagManager\Template\Tag\BaseTag;
use Piwik\Validators\NotEmpty;
use Piwik\Validators\CharacterLength;

class GoogleAds extends BaseTag
{
public function getCategory() {
return self::CATEGORY_REMARKETING;
}

public function getIcon() {
return 'plugins/TagManager/images/icons/googleads.svg';
}

public function getParameters() {
return array(
$this->makeSetting('conversionID', '', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = 'Conversion ID';
$field->customUiControlTemplateFile = self::FIELD_TEMPLATE_VARIABLE;
$field->validators[] = new NotEmpty();
}),
$this->makeSetting('conversionLabel', '', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = 'Conversion label';
$field->customUiControlTemplateFile = self::FIELD_TEMPLATE_VARIABLE;
$field->validators[] = new NotEmpty();
}),
$this->makeSetting('conversionValue', 0, FieldConfig::TYPE_FLOAT, function (FieldConfig $field) {
$field->title = 'Conversion value';
$field->customUiControlTemplateFile = self::FIELD_TEMPLATE_VARIABLE;
}),
$this->makeSetting('conversionOrder', '', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = 'Conversion order number';
$field->customUiControlTemplateFile = self::FIELD_TEMPLATE_VARIABLE;
}),
$this->makeSetting('conversionCurrency', '', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = 'Conversion currency code';
$field->customUiControlTemplateFile = self::FIELD_TEMPLATE_VARIABLE;
$field->validators[] = new CharacterLength(3, 3); // e.g. 'EUR'
}),
$this->makeSetting('conversionFormat', 3, FieldConfig::TYPE_INT, function (FieldConfig $field) {
$field->title = 'Conversion Format';
$field->availableValues = [
1 => "show a 1-line notification to visitors",
2 => "show a 2-line notification to visitors",
3 => "show no notification to visitors"
]; // from https://stackoverflow.com/a/16108587/4398037
$field->uiControl = FieldConfig::UI_CONTROL_SINGLE_SELECT;
}),
$this->makeSetting('conversionColor', '', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = 'Conversion Color'; # e.g. 'ffffff'
$field->customUiControlTemplateFile = self::FIELD_TEMPLATE_VARIABLE;
}),
$this->makeSetting('conversionLanguage', '', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = 'Conversion Language';
$field->customUiControlTemplateFile = self::FIELD_TEMPLATE_VARIABLE;
$field->validators[] = new CharacterLength(2, 2); // e.g. 'de'
}),
$this->makeSetting('tagParameters', [], FieldConfig::TYPE_ARRAY, function (FieldConfig $field) {
$field->title = 'Tag Parameters'; # e.g. 'ffffff'
$field->uiControl = FieldConfig::UI_CONTROL_MULTI_TUPLE;
$field1 = new FieldConfig\MultiPair('Parameter Name', 'parameter', FieldConfig::UI_CONTROL_TEXT);
$field2 = new FieldConfig\MultiPair('Value', 'value', FieldConfig::UI_CONTROL_TEXT);
$field2->customUiControlTemplateFile = self::FIELD_TEMPLATE_VARIABLE;
$field->uiControlAttributes['field1'] = $field1->toArray();
$field->uiControlAttributes['field2'] = $field2->toArray();
}),
);
}

}
10 changes: 10 additions & 0 deletions images/icons/googleads.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@
"GettingStartedWhatIfUnsupported": "What if a tag, trigger, or variable I need is not supported yet?",
"GettingStartedCustomTags": "There are custom tags, triggers, and variables available to let you implement pretty much any use case you need.",
"GettingStartedContributeTags": "If you use features regularly which are not available yet, or you have a product you want to integrate into the Tag Manager, please check out our %1$sdeveloper documentation%2$s on how to add your own tags, triggers, and variables. It is really easy.",
"GoogleAdsTagName": "Google Ads Conversion Tracking",
"GoogleAdsTagDescription": "Google Ads conversion tracking",
"GoogleAdsTagHelp": "",
"GoogleAnalyticsUniversalTagDescription": "Google Analytics is a web analytics service offered by Google.",
"GoogleAnalyticsUniversalTagHelp": "This tag lets you track website pageviews into your Google Analytics. To obtain the Property-ID please log in to your Google Analytics account.",
"GoogleAnalyticsUniversalTagName": "Google Analytics (Universal)",
Expand Down