-
Can't remember the fancy name of these coding styles, but instead of:
return function() { if(expression) {you should be using:
return function() { if(expression) {This helps the compiler when we start minifying the code.
-
Remove the
doubleDelegatemethod onAnalyticsClient. It should be up to the client code using theAnalyticsClienton how to initialise the object. -
Minor code consistency issues. E.g. some function parameters are specified with spaces:
function(param1, param2)and some without:function(param1,param2). -
Remove
setTimeout()on line 142 as it seems unnecessary (unless he can clarify?). -
Remove
location.reload()on line 148. This may just have been for debug purposes (?) but ultimately it's going to have a negative affect on the user experience. -
If the server to which the client sends events to will change on a per product basis, then I would suggest passing the server host through to
AnalyticsClientas a constructor parameter:AC = new AnalyticsClient('http://myhost.com'); -
Make sure you pass the code through a minifier to remove the code comments.
-
The object has been designed using a constructor and then adding a load of instance methods such as
addEventandcreatePageLoadDatato the prototype. This gives the impression that the AnalyticsClient has been designed to be instantiated multiple times. If this is not the case (which I assume it isn't) I would simplify the object by making it an object literal:var AnalyticsClient = { addEvent: function() {}, createPageLoadData: function() {} ... };(Maybe look into using the module pattern to separate his public and private api.)
-
Just a heads up…the
window.performanceapi is fairly recent and the comments about this object providing support for IE8+ is slightly misleading (it certainly isn't available in IE8!). -
The success callback on line 147 should probably be passed in to the object at runtime to allow for maximum flexibility.
-
On line 34, I'd change:
new Date().getTime()to(new Date()).getTime()just to be safe. -
Code comment on line 41 seems redundant.
-
Line 34 makes it hard to read the keys/values on the object he's pushing onto
this.events. For clarity, expand it onto multiple lines. -
If there's only ever going to be one event pushed on to the
this.eventsarray before it's sent to the server, you could clean up lines 91-92 by usingvar events = this.events.pop();instead. (Alternatively, why use an array at all?) -
AC_PRODUCTon line 1 is floating around in global space. Either remove the variable on line 34 and reference "t1" directly, or pass the variable in at runtime to the constructor. Alternatively, internalise the property onto the object if using a literal as suggested in (8.)
Created
February 5, 2013 11:03
-
-
Save danscotton/4713751 to your computer and use it in GitHub Desktop.
AnalyticsClient Feedback
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment