@ninetailed/experience.js-gatsby 7.5.0-beta.9 → 7.6.0-beta.1

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.
package/Tracker.js CHANGED
@@ -16,22 +16,31 @@ const usePrevious = value => {
16
16
  return ref.current;
17
17
  };
18
18
  const Executor = ({
19
- location
19
+ location,
20
+ onRouteChange
20
21
  }) => {
21
- const {
22
- page
23
- } = experience_jsReact.useNinetailed();
24
- const previousPathname = usePrevious(location);
25
- const pathname = location.pathname;
22
+ const ninetailed = experience_jsReact.useNinetailed();
23
+ const previousHref = usePrevious(location.href);
26
24
  React.useEffect(() => {
27
- if (pathname !== previousPathname) {
28
- page();
25
+ if (location.href !== previousHref) {
26
+ if (typeof onRouteChange === 'function') {
27
+ onRouteChange({
28
+ isInitialRoute: !previousHref,
29
+ url: location.href
30
+ }, ninetailed);
31
+ } else {
32
+ ninetailed.page();
33
+ }
29
34
  }
30
- }, [pathname, previousPathname, page]);
35
+ }, [location.href, previousHref, ninetailed, onRouteChange]);
31
36
  return null;
32
37
  };
33
- const Tracker = () => {
34
- return /*#__PURE__*/React__default["default"].createElement(router.Location, null, location => /*#__PURE__*/React__default["default"].createElement(Executor, Object.assign({}, location)));
38
+ const Tracker = ({
39
+ onRouteChange
40
+ }) => {
41
+ return /*#__PURE__*/React__default["default"].createElement(router.Location, null, location => /*#__PURE__*/React__default["default"].createElement(Executor, Object.assign({}, location, {
42
+ onRouteChange: onRouteChange
43
+ })));
35
44
  };
36
45
 
37
46
  exports.Tracker = Tracker;
package/_tslib.js ADDED
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ /******************************************************************************
4
+ Copyright (c) Microsoft Corporation.
5
+
6
+ Permission to use, copy, modify, and/or distribute this software for any
7
+ purpose with or without fee is hereby granted.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
16
+ ***************************************************************************** */
17
+
18
+ function __rest(s, e) {
19
+ var t = {};
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
21
+ t[p] = s[p];
22
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
23
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
24
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
25
+ t[p[i]] = s[p[i]];
26
+ }
27
+ return t;
28
+ }
29
+
30
+ function __awaiter(thisArg, _arguments, P, generator) {
31
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
32
+ return new (P || (P = Promise))(function (resolve, reject) {
33
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
34
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
35
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
36
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
37
+ });
38
+ }
39
+
40
+ exports.__awaiter = __awaiter;
41
+ exports.__rest = __rest;
package/gatsby-browser.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var _tslib = require('./_tslib.js');
5
6
  var React = require('react');
6
7
  var experience_js = require('@ninetailed/experience.js');
7
8
  var experience_jsReact = require('@ninetailed/experience.js-react');
@@ -41,6 +42,11 @@ const isSerializedPreviewPlugin = options => {
41
42
  const WrapRootElement = ({
42
43
  children
43
44
  }) => {
45
+ const _a = deserializePluginOptionFunctions(loaders_ninetailedPlugins.options),
46
+ {
47
+ onRouteChange
48
+ } = _a,
49
+ functions = _tslib.__rest(_a, ["onRouteChange"]);
44
50
  if (!ninetailed) {
45
51
  const resolvedPlugins = loaders_ninetailedPlugins.plugins.map(({
46
52
  PluginCtor,
@@ -63,9 +69,9 @@ const WrapRootElement = ({
63
69
  preview,
64
70
  url,
65
71
  locale,
66
- requestTimeout
72
+ requestTimeout,
73
+ useClientSideEvaluation
67
74
  } = loaders_ninetailedPlugins.options;
68
- const functions = deserializePluginOptionFunctions(loaders_ninetailedPlugins.options);
69
75
  ninetailed = new experience_js.Ninetailed({
70
76
  clientId,
71
77
  environment,
@@ -74,12 +80,15 @@ const WrapRootElement = ({
74
80
  url,
75
81
  plugins: resolvedPlugins,
76
82
  locale,
77
- requestTimeout
83
+ requestTimeout,
84
+ useClientSideEvaluation
78
85
  }, functions));
79
86
  }
80
87
  return /*#__PURE__*/React__default["default"].createElement(experience_jsReact.NinetailedProvider, {
81
88
  ninetailed: ninetailed
82
- }, /*#__PURE__*/React__default["default"].createElement(Tracker.Tracker, null), children);
89
+ }, /*#__PURE__*/React__default["default"].createElement(Tracker.Tracker, {
90
+ onRouteChange: onRouteChange
91
+ }), children);
83
92
  };
84
93
  const wrapRootElement = (args, options) => {
85
94
  const {
package/gatsby-node.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var _tslib = require('./_tslib.js');
5
6
  var require$$0 = require('path');
6
7
  var omit = require('lodash/omit');
7
8
 
@@ -10,43 +11,6 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
10
11
  var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
11
12
  var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
12
13
 
13
- /******************************************************************************
14
- Copyright (c) Microsoft Corporation.
15
-
16
- Permission to use, copy, modify, and/or distribute this software for any
17
- purpose with or without fee is hereby granted.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
20
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
21
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
22
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
24
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25
- PERFORMANCE OF THIS SOFTWARE.
26
- ***************************************************************************** */
27
-
28
- function __rest(s, e) {
29
- var t = {};
30
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
31
- t[p] = s[p];
32
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
33
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
34
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
35
- t[p[i]] = s[p[i]];
36
- }
37
- return t;
38
- }
39
-
40
- function __awaiter(thisArg, _arguments, P, generator) {
41
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
42
- return new (P || (P = Promise))(function (resolve, reject) {
43
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
44
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
45
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
46
- step((generator = generator.apply(thisArg, _arguments || [])).next());
47
- });
48
- }
49
-
50
14
  /**
51
15
  * Constructs an object/context holding serialized functions along with an array of their names
52
16
  * @param objectToSerialize - The object to serialize
@@ -72,7 +36,7 @@ const serializePluginOptionFunctions = pluginOptions => {
72
36
  const {
73
37
  serializedFunctionsNames: serializedOptionFunctionNames
74
38
  } = serializedOptionsContext,
75
- serializedOptionFunctions = __rest(serializedOptionsContext, ["serializedFunctionsNames"]);
39
+ serializedOptionFunctions = _tslib.__rest(serializedOptionsContext, ["serializedFunctionsNames"]);
76
40
  if (!pluginOptions.customOptions) {
77
41
  return {
78
42
  serializedOptionFunctions,
@@ -85,7 +49,7 @@ const serializePluginOptionFunctions = pluginOptions => {
85
49
  const {
86
50
  serializedFunctionsNames: serializedCustomOptionFunctionNames
87
51
  } = serializedCustomOptionsContext,
88
- serializedCustomOptionFunctions = __rest(serializedCustomOptionsContext, ["serializedFunctionsNames"]);
52
+ serializedCustomOptionFunctions = _tslib.__rest(serializedCustomOptionsContext, ["serializedFunctionsNames"]);
89
53
  return {
90
54
  serializedOptionFunctions,
91
55
  serializedOptionFunctionNames,
@@ -102,7 +66,8 @@ const pluginOptionsSchema = ({
102
66
  'any.required': '"clientId" needs to be specified. Get your clientId from the dashboard.'
103
67
  }),
104
68
  environment: Joi.string(),
105
- ninetailedPlugins: Joi.array()
69
+ ninetailedPlugins: Joi.array(),
70
+ useClientSideEvaluation: Joi.boolean().optional().default(false)
106
71
  });
107
72
  };
108
73
  /**
@@ -137,7 +102,7 @@ const createPages = ({
137
102
  actions,
138
103
  store,
139
104
  graphql
140
- }) => __awaiter(void 0, void 0, void 0, function* () {
105
+ }) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
141
106
  const ninetailedGatsbyPlugin = store.getState().flattenedPlugins.find(plugin => plugin.name === '@ninetailed/experience.js-gatsby');
142
107
  if (!ninetailedGatsbyPlugin) {
143
108
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js-gatsby",
3
- "version": "7.5.0-beta.9",
3
+ "version": "7.6.0-beta.1",
4
4
  "keywords": [
5
5
  "gatsby",
6
6
  "gatsby-plugin",
@@ -19,8 +19,8 @@
19
19
  "type": "commonjs",
20
20
  "types": "./index.d.ts",
21
21
  "dependencies": {
22
- "@ninetailed/experience.js": "7.5.0-beta.9",
23
- "@ninetailed/experience.js-react": "7.5.0-beta.9",
22
+ "@ninetailed/experience.js": "7.6.0-beta.1",
23
+ "@ninetailed/experience.js-react": "7.6.0-beta.1",
24
24
  "gatsby-plugin-utils": "3.19.0",
25
25
  "lodash": "4.17.21"
26
26
  }
@@ -1 +1,11 @@
1
- export declare const Tracker: () => JSX.Element;
1
+ import React from 'react';
2
+ import { NinetailedInstance } from '@ninetailed/experience.js';
3
+ type OnRouteChange = (routeInfo: {
4
+ isInitialRoute: boolean;
5
+ url: string;
6
+ }, ninetailed: NinetailedInstance) => void;
7
+ type TrackerProps = {
8
+ onRouteChange?: OnRouteChange;
9
+ };
10
+ export declare const Tracker: React.FC<TrackerProps>;
11
+ export {};