@@ -101,19 +101,41 @@ var client = function(sitekey) {
101101 this . setShuffleAndLimitTo = function ( shuffleAndLimitTo ) { this . settings . setShuffleAndLimitTo ( shuffleAndLimitTo ) ; }
102102 this . setFuzzyMatch = function ( fuzzy ) { this . settings . setFuzzyMatch ( fuzzy ) ; }
103103 this . setCollectAnalytics = function ( collectAnalytics ) { this . settings . setCollectAnalytics ( collectAnalytics ) ; }
104- this . searchResultClicked = function ( documentId , position ) {
105- var data = {
106- action : 'click' ,
107- session : this . sessionId ,
108- keyword : this . settings . getSettings ( ) . keyword ,
109- docid : documentId ,
110- position : position
111- } ;
112- sendStats ( this . sitekey , data ) ;
104+ this . setStatsSessionId = function ( id ) { this . sessionId = id ; }
105+ this . getStatsSessionId = function ( ) { return this . sessionId ; }
106+
107+ this . sendStatsEvent = function ( type , keyword , data ) {
108+ if ( type === 'search' ) {
109+ var data = {
110+ action : 'search' ,
111+ session : this . sessionId ,
112+ keyword : keyword ,
113+ numberOfResults : data . numberOfResults
114+ } ;
115+ sendStats ( this . sitekey , data ) ;
116+ }
117+
118+ else if ( type === 'click' ) {
119+ var data = {
120+ action : 'click' ,
121+ session : this . sessionId ,
122+ keyword : keyword ,
123+ docid : data . documentId ,
124+ position : data . position
125+ } ;
126+ sendStats ( this . sitekey , data ) ;
127+ }
128+
129+ else {
130+ throw "Illegal sendStatsEvent type parameters. Should be search or click)" ;
131+ }
113132 }
114133
134+
115135 // Deprecated
116- this . useFuzzyMatch = function ( use ) { this . settings . setFuzzyMatch ( use ) ; }
136+ this . searchResultClicked = function ( documentId , position ) {
137+ this . sendStatsEvent ( 'click' , this . settings . getSettings ( ) . keyword , { documentId : documentId , position : position } ) ;
138+ }
117139}
118140
119141module . exports = client ;
0 commit comments