coveo.analytics 2.20.13 → 2.20.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,7 +43,10 @@ export declare class CoveoInsightClient {
43
43
  logPagerNumber(meta: PagerMetadata): Promise<void | import("../events").CustomEventResponse>;
44
44
  logPagerNext(meta: PagerMetadata): Promise<void | import("../events").CustomEventResponse>;
45
45
  logPagerPrevious(meta: PagerMetadata): Promise<void | import("../events").CustomEventResponse>;
46
+ logDidYouMeanAutomatic(): Promise<void | import("../events").SearchEventResponse>;
47
+ logDidYouMeanClick(): Promise<void | import("../events").SearchEventResponse>;
46
48
  logResultsSort(metadata: ResultsSortMetadata): Promise<void | import("../events").SearchEventResponse>;
49
+ logSearchboxSubmit(): Promise<void | import("../events").SearchEventResponse>;
47
50
  logContextChanged(meta: ContextChangedMetadata): Promise<void | import("../events").SearchEventResponse>;
48
51
  logExpandToFullUI(meta: ExpandToFullUIMetadata): Promise<void | import("../events").CustomEventResponse>;
49
52
  private getBaseCustomEventRequest;
@@ -1,2 +1,2 @@
1
- export declare const ReactNativeRuntimeWarning = "\n We've detected you're using React Native but have not provided the corresponding runtime, \n for an optimal experience please install @react-native-async-storage/async-storage and instantiate \n your analytics client as follows:\n \n import {ReactNativeRuntime} from 'coveo.analytics/react-native';\n \n const analytics = new CoveoAnalytics({\n ...your options,\n runtimeEnvironment: new ReactNativeRuntime();\n })\n ";
1
+ export declare const ReactNativeRuntimeWarning = "\n We've detected you're using React Native but have not provided the corresponding runtime, \n for an optimal experience please install @react-native-async-storage/async-storage and instantiate \n your analytics client as follows:\n \n import {ReactNativeRuntime} from 'coveo.analytics/src/react-native';\n \n const analytics = new CoveoAnalyticsClient({\n ...your options,\n runtimeEnvironment: new ReactNativeRuntime({\n baseUrl: '...',\n });\n })\n ";
2
2
  export declare function isReactNative(): boolean;
@@ -751,11 +751,13 @@ const ReactNativeRuntimeWarning = `
751
751
  for an optimal experience please install @react-native-async-storage/async-storage and instantiate
752
752
  your analytics client as follows:
753
753
 
754
- import {ReactNativeRuntime} from 'coveo.analytics/react-native';
754
+ import {ReactNativeRuntime} from 'coveo.analytics/src/react-native';
755
755
 
756
- const analytics = new CoveoAnalytics({
756
+ const analytics = new CoveoAnalyticsClient({
757
757
  ...your options,
758
- runtimeEnvironment: new ReactNativeRuntime();
758
+ runtimeEnvironment: new ReactNativeRuntime({
759
+ baseUrl: '...',
760
+ });
759
761
  })
760
762
  `;
761
763
  function isReactNative() {
@@ -1879,9 +1881,18 @@ class CoveoInsightClient {
1879
1881
  logPagerPrevious(meta) {
1880
1882
  return this.logCustomEvent(SearchPageEvents.pagerPrevious, meta);
1881
1883
  }
1884
+ logDidYouMeanAutomatic() {
1885
+ return this.logSearchEvent(SearchPageEvents.didyoumeanAutomatic);
1886
+ }
1887
+ logDidYouMeanClick() {
1888
+ return this.logSearchEvent(SearchPageEvents.didyoumeanClick);
1889
+ }
1882
1890
  logResultsSort(metadata) {
1883
1891
  return this.logSearchEvent(SearchPageEvents.resultsSort, metadata);
1884
1892
  }
1893
+ logSearchboxSubmit() {
1894
+ return this.logSearchEvent(SearchPageEvents.searchboxSubmit);
1895
+ }
1885
1896
  logContextChanged(meta) {
1886
1897
  const context = extractContextFromMetadata(meta);
1887
1898
  const { caseId, caseNumber } = meta;
package/dist/library.js CHANGED
@@ -82507,7 +82507,7 @@ var NoopRuntime = (function () {
82507
82507
  var API_KEY_PREFIX = 'xx';
82508
82508
  var isApiKey = function (token) { return (token === null || token === void 0 ? void 0 : token.startsWith(API_KEY_PREFIX)) || false; };
82509
82509
 
82510
- var ReactNativeRuntimeWarning = "\n We've detected you're using React Native but have not provided the corresponding runtime, \n for an optimal experience please install @react-native-async-storage/async-storage and instantiate \n your analytics client as follows:\n \n import {ReactNativeRuntime} from 'coveo.analytics/react-native';\n \n const analytics = new CoveoAnalytics({\n ...your options,\n runtimeEnvironment: new ReactNativeRuntime();\n })\n ";
82510
+ var ReactNativeRuntimeWarning = "\n We've detected you're using React Native but have not provided the corresponding runtime, \n for an optimal experience please install @react-native-async-storage/async-storage and instantiate \n your analytics client as follows:\n \n import {ReactNativeRuntime} from 'coveo.analytics/src/react-native';\n \n const analytics = new CoveoAnalyticsClient({\n ...your options,\n runtimeEnvironment: new ReactNativeRuntime({\n baseUrl: '...',\n });\n })\n ";
82511
82511
  function isReactNative() {
82512
82512
  return typeof navigator != 'undefined' && navigator.product == 'ReactNative';
82513
82513
  }
@@ -84288,9 +84288,18 @@ var CoveoInsightClient = (function () {
84288
84288
  CoveoInsightClient.prototype.logPagerPrevious = function (meta) {
84289
84289
  return this.logCustomEvent(SearchPageEvents.pagerPrevious, meta);
84290
84290
  };
84291
+ CoveoInsightClient.prototype.logDidYouMeanAutomatic = function () {
84292
+ return this.logSearchEvent(SearchPageEvents.didyoumeanAutomatic);
84293
+ };
84294
+ CoveoInsightClient.prototype.logDidYouMeanClick = function () {
84295
+ return this.logSearchEvent(SearchPageEvents.didyoumeanClick);
84296
+ };
84291
84297
  CoveoInsightClient.prototype.logResultsSort = function (metadata) {
84292
84298
  return this.logSearchEvent(SearchPageEvents.resultsSort, metadata);
84293
84299
  };
84300
+ CoveoInsightClient.prototype.logSearchboxSubmit = function () {
84301
+ return this.logSearchEvent(SearchPageEvents.searchboxSubmit);
84302
+ };
84294
84303
  CoveoInsightClient.prototype.logContextChanged = function (meta) {
84295
84304
  var context = extractContextFromMetadata(meta);
84296
84305
  var caseId = meta.caseId, caseNumber = meta.caseNumber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coveo.analytics",
3
- "version": "2.20.13",
3
+ "version": "2.20.16",
4
4
  "description": "📈 Coveo analytics client (node and browser compatible) ",
5
5
  "main": "dist/library.js",
6
6
  "module": "dist/library.es.js",
@@ -12,7 +12,7 @@
12
12
  "build": "rollup -c",
13
13
  "start": "rollup -c -w --environment SERVE",
14
14
  "test": "jest --clearCache && jest --coverage",
15
- "test:watch": "jest --watch",
15
+ "test:watch": "jest --clearCache && jest --watch",
16
16
  "prepare-deploy": "mkdir -p deploy && cp dist/coveoua*.js dist/coveoua*.js.map deploy",
17
17
  "clean": "rimraf -rf dist dist_test coverage"
18
18
  },
@@ -4,7 +4,7 @@ import {IAnalyticsRequestOptions} from './analyticsRequestClient';
4
4
  import {CookieAndLocalStorage, CookieStorage, NullStorage} from '../storage';
5
5
  import HistoryStore from '../history';
6
6
  import {mockFetch} from '../../tests/fetchMock';
7
- import {BrowserRuntime, NoopRuntime} from './runtimeEnvironment';
7
+ import {BrowserRuntime} from './runtimeEnvironment';
8
8
  import * as doNotTrack from '../donottrack';
9
9
  import {Cookie} from '../cookieutils';
10
10
 
@@ -261,11 +261,26 @@ describe('InsightClient', () => {
261
261
  expectMatchCustomEventPayload(SearchPageEvents.pagerPrevious, meta);
262
262
  });
263
263
 
264
+ it('should send proper payload for #didyoumeanAutomatic', async () => {
265
+ await client.logDidYouMeanAutomatic();
266
+ expectMatchPayload(SearchPageEvents.didyoumeanAutomatic);
267
+ });
268
+
269
+ it('should send proper payload for #didyoumeanClick', async () => {
270
+ await client.logDidYouMeanClick();
271
+ expectMatchPayload(SearchPageEvents.didyoumeanClick);
272
+ });
273
+
264
274
  it('should send proper payload for #resultsSort', async () => {
265
275
  await client.logResultsSort({resultsSortBy: 'date ascending'});
266
276
  expectMatchPayload(SearchPageEvents.resultsSort, {resultsSortBy: 'date ascending'});
267
277
  });
268
278
 
279
+ it('should send proper payload for #searchboxSubmit', async () => {
280
+ await client.logSearchboxSubmit();
281
+ expectMatchPayload(SearchPageEvents.searchboxSubmit);
282
+ });
283
+
269
284
  it('should enable analytics tracking by default', () => {
270
285
  const c = new CoveoInsightClient({}, provider);
271
286
  expect(c.coveoAnalyticsClient instanceof CoveoAnalyticsClient).toBe(true);
@@ -146,10 +146,22 @@ export class CoveoInsightClient {
146
146
  return this.logCustomEvent(SearchPageEvents.pagerPrevious, meta);
147
147
  }
148
148
 
149
+ public logDidYouMeanAutomatic() {
150
+ return this.logSearchEvent(SearchPageEvents.didyoumeanAutomatic);
151
+ }
152
+
153
+ public logDidYouMeanClick() {
154
+ return this.logSearchEvent(SearchPageEvents.didyoumeanClick);
155
+ }
156
+
149
157
  public logResultsSort(metadata: ResultsSortMetadata) {
150
158
  return this.logSearchEvent(SearchPageEvents.resultsSort, metadata);
151
159
  }
152
160
 
161
+ public logSearchboxSubmit() {
162
+ return this.logSearchEvent(SearchPageEvents.searchboxSubmit);
163
+ }
164
+
153
165
  public logContextChanged(meta: ContextChangedMetadata) {
154
166
  const context = extractContextFromMetadata(meta);
155
167
 
@@ -1,2 +1,3 @@
1
+ // TODO: v3 add in "coveo.analytics/react-native" subpackage
1
2
  export {ReactNativeRuntime} from './react-native-runtime';
2
3
  export {ReactNativeStorage} from './react-native-storage';
@@ -8,6 +8,8 @@ export class ReactNativeRuntime implements IRuntimeEnvironment {
8
8
  public storage: WebStorage;
9
9
  public client: AnalyticsFetchClient;
10
10
 
11
+ // TODO: v3 switch to ClientOptions type, add default options
12
+ // TODO: v3 reuse own ReactNativeStorage to implement VisitorIdProvider's getCurrentVisitorId, setCurrentVisitorId
11
13
  constructor(clientOptions: IAnalyticsClientOptions) {
12
14
  this.storage = new ReactNativeStorage();
13
15
  this.client = new AnalyticsFetchClient(clientOptions);
@@ -3,11 +3,13 @@ export const ReactNativeRuntimeWarning = `
3
3
  for an optimal experience please install @react-native-async-storage/async-storage and instantiate
4
4
  your analytics client as follows:
5
5
 
6
- import {ReactNativeRuntime} from 'coveo.analytics/react-native';
6
+ import {ReactNativeRuntime} from 'coveo.analytics/src/react-native';
7
7
 
8
- const analytics = new CoveoAnalytics({
8
+ const analytics = new CoveoAnalyticsClient({
9
9
  ...your options,
10
- runtimeEnvironment: new ReactNativeRuntime();
10
+ runtimeEnvironment: new ReactNativeRuntime({
11
+ baseUrl: '...',
12
+ });
11
13
  })
12
14
  `;
13
15
 
@@ -0,0 +1,27 @@
1
+ import CoveoAnalyticsClient from '../client/analytics';
2
+ import {ReactNativeRuntime} from './index';
3
+
4
+ describe('ReactNativeRuntime', () => {
5
+ let runtimeEnvironment: ReactNativeRuntime;
6
+ let client: CoveoAnalyticsClient;
7
+
8
+ beforeEach(() => {
9
+ runtimeEnvironment = new ReactNativeRuntime({
10
+ baseUrl: 'https://www.coveo.com',
11
+ visitorIdProvider: {getCurrentVisitorId: jest.fn(), setCurrentVisitorId: jest.fn()},
12
+ });
13
+ client = new CoveoAnalyticsClient({runtimeEnvironment});
14
+ });
15
+
16
+ it('should call "storage.getItem" when getting the visitor ID', async () => {
17
+ spyOn(runtimeEnvironment.storage, 'getItem');
18
+ await client.getCurrentVisitorId();
19
+ expect(runtimeEnvironment.storage.getItem).toHaveBeenCalled();
20
+ });
21
+
22
+ it('should call "storage.getItem" when getting the visitor ID', async () => {
23
+ spyOn(runtimeEnvironment.storage, 'setItem');
24
+ await client.setCurrentVisitorId('myid');
25
+ expect(runtimeEnvironment.storage.setItem).toHaveBeenCalled();
26
+ });
27
+ });