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

add Zendesk Chat Tag #58

Merged
merged 2 commits into from
Aug 19, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions Template/Tag/ZendeskChatTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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\Settings\Setting;
use Piwik\Validators\CharacterLength;
use Piwik\Validators\NotEmpty;
use Piwik\Validators\NumberRange;

class ZendeskChatTag extends BaseTag
{
public function getCategory() {
return self::CATEGORY_SOCIAL;
}

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

public function getParameters() {
return array(
$this->makeSetting('zendeskChatId', '', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = 'Zendesk Chat ID';
$field->description = 'You can get the Site ID by logging into Zendesk Chat, going to "Settings" and clicking on "Widget". The Site ID has typically about 32 characters and is the text coming directly after "https://v2.zopim.com/?", for example "123451c27295ad739e46b6b1".';
$field->validators[] = new NotEmpty();
$field->validators[] = new CharacterLength(20, 40);
$field->validate = function ($value, Setting $setting) {
if (substr($value, 0, 1) === "?") {
throw new \Exception("The Chat ID shouldn't include the staring '?'");
}
};

}),
);
}

}
25 changes: 25 additions & 0 deletions Template/Tag/ZendeskChatTag.web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(function () {
return function (parameters, TagManager) {
this.fire = function () {
var zendeskChatId = parameters.get("zendeskChatId");
window.$zopim || (function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, maybe we could add a check to execute it only if a zendeskChatId exists: if (! zendeskChatId) {return;}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While a check never hurts, I can't think of a way it could be undefined if it is required.

var z = $zopim = function (c) {
z._.push(c)
};
var script = z.s = document.createElement("script");
var e = document.getElementsByTagName("script")[0];
z.set = function (o) {
z.set._.push(o)
};
z._ = [];
z.set._ = [];
script.async = true;
script.setAttribute("charset", "utf-8");
script.src = "https://v2.zopim.com/?" + zendeskChatId;
z.t = +new Date;
script.type = "text/javascript";
e.parentNode.insertBefore(script, e)
})();
};
};
})();
5 changes: 5 additions & 0 deletions images/icons/zendesk_chat.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@
"WindowLoadedTriggerName": "Window Loaded",
"WindowUnloadTriggerDescription": "Triggered just before the browser window is closed or when the user navigates to a different page.",
"WindowUnloadTriggerHelp": "This trigger identifies the event when a user is actually closing the current page compared to the \"Window Leave\" trigger which triggers when the user is about to leave your page. Either by navigating to another page within the current browser tab, or by completely closing the tab.",
"WindowUnloadTriggerName": "Window Unload"
"WindowUnloadTriggerName": "Window Unload",
"ZendeskChatTagDescription": "Reach your customers, instantly via web, mobile, and messaging.",
"ZendeskChatTagHelp": "This tag allows you to add the Zendesk Chat form to your website.",
"ZendeskChatTagName": "Zendesk Chat (formerly Zopim)"
}
}