-
Notifications
You must be signed in to change notification settings - Fork 55
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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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 '?'"); | ||
} | ||
}; | ||
|
||
}), | ||
); | ||
} | ||
|
||
} |
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,25 @@ | ||
(function () { | ||
return function (parameters, TagManager) { | ||
this.fire = function () { | ||
var zendeskChatId = parameters.get("zendeskChatId"); | ||
window.$zopim || (function () { | ||
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) | ||
})(); | ||
}; | ||
}; | ||
})(); |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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;}
There was a problem hiding this comment.
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.