Adding Google Analytics Event tracking to Zendesk buttons

In order to gauge the popularity of Help Centre articles and Community posts in Zendesk, I thought it may be beneficial to add event tracking to voting and subscription buttons.

The code below is my first-pass at logging voting on Community posts:
// post GA event when a vote is cast $('.vote-down').click( function() { ga('send', 'event', 'Question', 'VoteDown', $(this).attr('data-vote-url'));
}); $('.vote-up').click( function() { ga('send', 'event', 'Question', 'VoteUp', $(this).attr('data-vote-url'));

This uses the ‘vote-up’ and ‘vote-down’ class to attach the code. These are present on the voting buttons for the original question and any comments that are added later.

The page updates itself when the buttons are clicked and this has the effect of removing the onclick() event until the page is refreshed. That’s something I’d like to look into in more detail. It may also be more ‘friendly’ to use the Question title instead of the vote URL as the event label (by swapping $(this).attr('data-vote-url') for $('h1.question-title').text()) , but these can be quite long.

Also, I need to consider whether it’s necessary to know the detail of what’s been up/down voted, or whether it’s sufficient to know which pages are getting most votes, which might indicate ‘hot’ topics that could be leveraged for commercial/marketing purposes.

The next code chunk records when visitors un/subscribe to an article in the main Help Centre:

// post GA event when an article is followed $('.article-subscribe').click( function() { ga('send', 'event', 'Article', 'Subscribe', $('.article-header h1').text().trim());
}); $('.article-unsubscribe').click( function() { ga('send', 'event', 'Article', 'Subscribe', $('.article-header h1').text().trim());

All code is added to the JS file in the Zendesk Help Centre theme customiser:

Paul Middleton

Read more posts by this author.

Illawarra, NSW
comments powered by Disqus

Subscribe to Funnel Vision

Get the latest posts delivered right to your inbox.

* indicates required