33 * @author dejun@visenze.com, @author rachel.ngo@visenze.com
44 */
55
6- import find from 'lodash.find' ;
7- import URI from 'jsuri' ;
86import va , { VAClient } from 'visenze-tracking-javascript' ;
97import { version } from './version.js' ;
108
@@ -17,9 +15,6 @@ const STAGING_ENDPOINT = 'https://search-dev.visenze.com';
1715const ANALYTICS_STAGING_ENDPOINT = 'https://staging-analytics.data.visenze.com/v3' ;
1816const SDK = 'visearch js sdk' ;
1917const SDK_VERSION = version ;
20- const QUERY_REQID = 'reqid' ;
21- const QUERY_IMNAME = 'im_name' ;
22- const QUERY_ACTION = 'action' ;
2318const RESULT_LOAD = 'result_load' ;
2419
2520function getSdkVersion ( ) : Record < string , string > {
@@ -29,13 +24,6 @@ function getSdkVersion(): Record<string, string> {
2924 } ;
3025}
3126
32- /**
33- * Get query parameters from url [URI] object
34- */
35- function getQueryParamValue ( uri : URI , name : string ) : unknown {
36- return find ( [ `__vi_${ name } ` , name ] , ( ) => uri . getQueryParamValue ( name ) ) ;
37- }
38-
3927export function ViSearch ( configs ?: Record < string , unknown > ) : ViSearchClient {
4028 const q : unknown [ ] = [ ] ;
4129 const settings : ViSearchSettings = {
@@ -149,41 +137,14 @@ export function ViSearch(configs?: Record<string, unknown>): ViSearchClient {
149137 function wrapCallback (
150138 productId : string | undefined ,
151139 callback : ( ( resp : ProductSearchResponse ) => void ) | undefined ,
152- resp : ProductSearchResponse
140+ resp : ProductSearchResponse ,
153141 ) : void {
154142 wrapExperimentResponse ( resp ) ;
155143 callback ?.( resp ) ;
156144 saveQueryId ( resp ) ;
157145 sendResultLoadEvent ( productId , resp ) ;
158146 }
159147
160- function sendRefClickEvent ( ) : void {
161- // For browser env
162- // Check the link of current page, to check if the page is come from a previous search click.
163- let refReqId : unknown = null ;
164- if ( document . referrer ) {
165- const refUri = new URI ( document . referrer ) ;
166- refReqId = getQueryParamValue ( refUri , QUERY_REQID ) ;
167- }
168- // Get reqid from current url or from its referrer url
169- const curUri = new URI ( window . location . href ) ;
170- const reqid = getQueryParamValue ( curUri , QUERY_REQID ) || refReqId ;
171- const imName = getQueryParamValue ( curUri , QUERY_IMNAME ) ;
172- // If reqid, action and imName are found in current page content, send event tracking.
173- if ( reqid && imName ) {
174- // Get event 'action' for page will set it as 'click' action by default if not specified.
175- const action = ( getQueryParamValue ( curUri , QUERY_ACTION ) as string ) || 'click' ;
176- prototypes . sendEvent ( action , {
177- queryId : getQueryParamValue ( curUri , QUERY_REQID ) ,
178- im_name : getQueryParamValue ( curUri , QUERY_IMNAME ) ,
179- } ) ;
180- }
181- }
182-
183- if ( typeof window !== 'undefined' ) {
184- sendRefClickEvent ( ) ;
185- }
186-
187148 const prototypes : ViSearchClient = {
188149 q,
189150 set : function ( key , value ) {
@@ -207,7 +168,7 @@ export function ViSearch(configs?: Record<string, unknown>): ViSearchClient {
207168 } ,
208169 ( err ) => {
209170 failure ?.( err ) ;
210- }
171+ } ,
211172 ) ;
212173 }
213174 } ,
0 commit comments