@@ -76,36 +76,7 @@ define([
76
76
77
77
this . startAutocomplete ( options ) ;
78
78
79
- //Autocomplete insight click conversion
80
- // TODO: Switch to insights plugin
81
- if ( algoliaConfig . ccAnalytics . enabled ) {
82
- $ ( document ) . on ( 'click' , '.algoliasearch-autocomplete-hit' , function ( ) {
83
- const $this = $ ( this ) ;
84
- if ( $this . data ( 'clicked' ) ) return ;
85
-
86
- const objectId = $this . attr ( 'data-objectId' ) ;
87
- const indexName = $this . attr ( 'data-index' ) ;
88
- const queryId = $this . attr ( 'data-queryId' ) ;
89
- const position = $this . attr ( 'data-position' ) ;
90
-
91
- let useCookie = algoliaConfig . cookieConfiguration
92
- . cookieRestrictionModeEnabled
93
- ? ! ! algoliaCommon . getCookie ( algoliaConfig . cookieConfiguration . consentCookieName )
94
- : true ;
95
- if ( useCookie !== false ) {
96
- algoliaInsights . initializeAnalytics ( ) ;
97
- const eventData = algoliaInsights . buildEventData (
98
- 'Clicked' ,
99
- objectId ,
100
- indexName ,
101
- position ,
102
- queryId
103
- ) ;
104
- algoliaInsights . trackClick ( eventData ) ;
105
- $this . attr ( 'data-clicked' , true ) ;
106
- }
107
- } ) ;
108
- }
79
+ this . trackClicks ( ) ;
109
80
110
81
if ( algoliaConfig . autocomplete . isNavigatorEnabled ) {
111
82
$ ( 'body' ) . append (
@@ -821,6 +792,41 @@ define([
821
792
} ,
822
793
}
823
794
) ;
824
- }
795
+ } ,
796
+
797
+ /**
798
+ * Autocomplete insight click conversion
799
+ */
800
+ trackClicks ( ) {
801
+ // TODO: Switch to insights plugin
802
+ if ( algoliaConfig . ccAnalytics . enabled ) {
803
+ $ ( document ) . on ( 'click' , '.algoliasearch-autocomplete-hit' , function ( ) {
804
+ const $this = $ ( this ) ;
805
+ if ( $this . data ( 'clicked' ) ) return ;
806
+
807
+ const objectId = $this . attr ( 'data-objectId' ) ;
808
+ const indexName = $this . attr ( 'data-index' ) ;
809
+ const queryId = $this . attr ( 'data-queryId' ) ;
810
+ const position = $this . attr ( 'data-position' ) ;
811
+
812
+ let useCookie = algoliaConfig . cookieConfiguration
813
+ . cookieRestrictionModeEnabled
814
+ ? ! ! algoliaCommon . getCookie ( algoliaConfig . cookieConfiguration . consentCookieName )
815
+ : true ;
816
+ if ( useCookie !== false ) {
817
+ algoliaInsights . initializeAnalytics ( ) ;
818
+ const eventData = algoliaInsights . buildEventData (
819
+ 'Clicked' ,
820
+ objectId ,
821
+ indexName ,
822
+ position ,
823
+ queryId
824
+ ) ;
825
+ algoliaInsights . trackClick ( eventData ) ;
826
+ $this . attr ( 'data-clicked' , true ) ;
827
+ }
828
+ } ) ;
829
+ }
830
+ } ,
825
831
} ) ;
826
832
} ) ;
0 commit comments