Skip to content

Instantly share code, notes, and snippets.

@gooley
Last active August 29, 2015 14:06
Show Gist options
  • Save gooley/4bd5d4ee851189696680 to your computer and use it in GitHub Desktop.
Save gooley/4bd5d4ee851189696680 to your computer and use it in GitHub Desktop.
Zendesk Helpcenter Instrumentation
// document head
// Put this script block inside the template for your document head, it will load and initialize the Preact logging javascript
<script>
window._preactq = window._preactq || [];
window._preactq.push(['_setCode', 'your_project_code']);
$(function(){
if(HelpCenter.user){
window._preactq.push(['_setPersonData', {
name: HelpCenter.user.name,
email: HelpCenter.user.email
}]);
(function() {
var preact = document.createElement('script'); preact.type = 'text/javascript'; preact.async = true;
preact.src = 'https://s3.amazonaws.com/lessneglect-cdn-01/js/preact-4.0.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(preact, s);
})();
}
});
</script>
// put each of these script tags in the page template specified by the comment preceding it.
// home
<script>$(function(){ _preactq.push(['_logEvent', { name: 'zendesk-helpcenter|viewed:helpcenter-home' }]); });</script>
// category
<script>$(function(){ _preactq.push(['_logEvent', { name: 'zendesk-helpcenter|viewed:helpcenter-category', note: '{{title}}' }]); });</script>
// section
<script>$(function(){ _preactq.push(['_logEvent', { name: 'zendesk-helpcenter|viewed:helpcenter-section', note: '{{title}}' }]); });</script>
// article
<script>$(function(){ _preactq.push(['_logEvent', { name: 'zendesk-helpcenter|viewed:helpcenter-article', note: '{{title}}' }]); });</script>
// contributions
<script>$(function(){ _preactq.push(['_logEvent', { name: 'zendesk-helpcenter|viewed:helpcenter-contributions' }]); });</script>
// following
<script>$(function(){ _preactq.push(['_logEvent', { name: 'zendesk-helpcenter|viewed:helpcenter-following' }]); });</script>
// my requests
<script>$(function(){ _preactq.push(['_logEvent', { name: 'zendesk-helpcenter|viewed:helpcenter-my-requests' }]); });</script>
// single request
<script>$(function(){ _preactq.push(['_logEvent', { name: 'zendesk-helpcenter|viewed:helpcenter-request', target_id: '{{request_id}}', note: '{{subject}}' }]); });</script>
// new request
<script>$(function(){ _preactq.push(['_logEvent', { name: 'zendesk-helpcenter|viewed:helpcenter-new-request' }]); });</script>
// search results
<script>$(function(){ _preactq.push(['_logEvent', { name: 'zendesk-helpcenter|viewed:helpcenter-search-results' }]); });</script>
// error
<script>$(function(){ _preactq.push(['_logEvent', { name: '!zendesk-helpcenter|errored:helpcenter-page', note: '{{error_message}}' }]); });</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment