track user interaction events in google analytics

this will track things like

form validation errors:
  * name of form (id or classname or page title)
  * which fields were invalid

viewing document previews
  * doc details
  * which service (google or scribd) used

Slow Ajax requests (things that take over 1 sec)
  *does not track things less than 1 sec

Change-Id: I569e405089df5acd983472cb834f35d41b1a4bf3
Reviewed-on: https://gerrit.instructure.com/6142
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Brian Whitmer <brian@instructure.com>
This commit is contained in:
Ryan Shaw 2011-10-12 11:37:23 -06:00
parent 395b0fdb07
commit 99a97badef
3 changed files with 11 additions and 6 deletions

View File

@ -19,13 +19,16 @@
I18n.scoped('instructure', function(I18n) {
// sends timing info of XHRs to google analytics so we can track ajax speed.
// (ONLY for ajax requests that took longer than a second)
$.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
var urlWithoutPageViewParam = options.url;
var start = new Date().getTime();
jqXHR.done(function(data, textStatus, jqXHR){
var duration = new Date().getTime() - start,
label = '{"requestingPage": "' + window.location + '," "status": "' + textStatus + '", "X-Request-Context-Id" : "' + jqXHR.getResponseHeader('X-Request-Context-Id') + '", "X-Runtime": ' + jqXHR.getResponseHeader('X-Runtime') + '}';
$.trackEvent('XHRs', urlWithoutPageViewParam, label, duration );
var duration = new Date().getTime() - start;
if (duration > 1000) {
var label = '{"requestingPage": "' + window.location + '," "status": "' + textStatus + '", "X-Request-Context-Id" : "' + jqXHR.getResponseHeader('X-Request-Context-Id') + '", "X-Runtime": ' + jqXHR.getResponseHeader('X-Runtime') + '}';
$.trackEvent('XHRs', urlWithoutPageViewParam, label, duration );
}
});
});

View File

@ -71,10 +71,11 @@ I18n.scoped('instructure', function(I18n) {
height: '400px'
}, $this.data(), options);
function tellAppIViewedThisInline(){
function tellAppIViewedThisInline(serviceUsed){
// if I have a url to ping back to the app that I viewed this file inline, ping it.
if (opts.attachment_view_inline_ping_url) {
$.ajaxJSON(opts.attachment_view_inline_ping_url, 'POST', {}, function() { }, function() { });
$.trackEvent('Doc Previews', serviceUsed, JSON.stringify(opts));
}
}
@ -110,7 +111,7 @@ I18n.scoped('instructure', function(I18n) {
// and http://groups.google.com/group/scribd-platform-developers/msg/46a4f12db73d02d8
this.childNodes[0].keyboardShortcutDown = this.childNodes[0].keyboardShortcutUp = function(){};
tellAppIViewedThisInline();
tellAppIViewedThisInline('scribd');
} else if (!INST.disableGooglePreviews && (!opts.mimeType || $.isPreviewable(opts.mimeType, 'google')) && opts.attachment_id || opts.public_url){
// else if it's something google docs preview can handle and we can get a public url to this document.
function loadGooglePreview(){
@ -122,7 +123,7 @@ I18n.scoped('instructure', function(I18n) {
$('<iframe src="' + googleDocPreviewUrl + '" height="' + opts.height + '" width="100%" />')
.appendTo($this)
.load(function(){
tellAppIViewedThisInline();
tellAppIViewedThisInline('google');
if ($.isFunction(opts.ready)) {
opts.ready();
}

View File

@ -845,6 +845,7 @@ I18n.scoped('instructure', function(I18n) {
}
if(hasErrors) {
$form.formErrors(errors);
$.trackEvent("Form Errors", this.attr('id') || this.attr('class') || document.title, JSON.stringify(errors));
return false;
}
return true;