@ninetailed/experience.js-next 7.5.3 → 7.6.0-beta.2

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/index.cjs.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/index";
@@ -38,13 +38,11 @@ function __rest(s, e) {
38
38
  }
39
39
 
40
40
  const Tracker = ({
41
- isFirstPageviewAlreadyTracked
41
+ onRouteChange
42
42
  }) => {
43
43
  const router$1 = router.useRouter();
44
- const {
45
- page
46
- } = experience_jsReact.useNinetailed();
47
- const lastFiredPageRef = react.useRef(isFirstPageviewAlreadyTracked ? 'tracked' : 'none');
44
+ const ninetailed = experience_jsReact.useNinetailed();
45
+ const lastFiredPageRef = react.useRef('none');
48
46
  react.useEffect(() => {
49
47
  experience_jsShared.logger.debug('Ninetailed Next.js Tracker', 'The useEffect hook to listen for route changes got called. On instantiation the last fired page is:', lastFiredPageRef.current);
50
48
  const handleRouteChange = url => {
@@ -56,7 +54,13 @@ const Tracker = ({
56
54
  });
57
55
  if (!isPageAlreadyTracked) {
58
56
  experience_jsShared.logger.debug('Ninetailed Next.js Tracker', 'Page is not tracked yet, calling the ninetailed.page function.');
59
- page();
57
+ if (typeof onRouteChange === 'function') {
58
+ onRouteChange({
59
+ isInitialRoute: lastFiredPageRef.current === 'none'
60
+ }, ninetailed);
61
+ } else {
62
+ ninetailed.page();
63
+ }
60
64
  experience_jsShared.logger.debug('Ninetailed Next.js Tracker', 'Page got tracked, setting the last fired page to the current url.', url);
61
65
  lastFiredPageRef.current = url;
62
66
  }
@@ -76,9 +80,13 @@ const NinetailedProvider = _a => {
76
80
  children
77
81
  } = _a,
78
82
  props = __rest(_a, ["children"]);
79
- return jsxRuntime.jsxs(experience_jsReact.NinetailedProvider, Object.assign({}, props, {
83
+ const {
84
+ onRouteChange
85
+ } = props,
86
+ providerProps = __rest(props, ["onRouteChange"]);
87
+ return jsxRuntime.jsxs(experience_jsReact.NinetailedProvider, Object.assign({}, providerProps, {
80
88
  children: [jsxRuntime.jsx(Tracker, {
81
- isFirstPageviewAlreadyTracked: false
89
+ onRouteChange: onRouteChange
82
90
  }), children]
83
91
  }));
84
92
  };
@@ -2,46 +2,30 @@ import { useNinetailed, NinetailedProvider as NinetailedProvider$1 } from '@nine
2
2
  export * from '@ninetailed/experience.js-react';
3
3
  export * from '@ninetailed/experience.js-plugin-ssr';
4
4
  export { decodeExperienceVariantsMap } from '@ninetailed/experience.js';
5
- import { jsxs, jsx } from 'react/jsx-runtime';
6
5
  import { useRef, useEffect } from 'react';
7
6
  import { useRouter } from 'next/router';
8
7
  import { logger } from '@ninetailed/experience.js-shared';
8
+ import { jsxs, jsx } from 'react/jsx-runtime';
9
9
 
10
- /******************************************************************************
11
- Copyright (c) Microsoft Corporation.
12
-
13
- Permission to use, copy, modify, and/or distribute this software for any
14
- purpose with or without fee is hereby granted.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
17
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
19
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
20
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
- PERFORMANCE OF THIS SOFTWARE.
23
- ***************************************************************************** */
24
-
25
- function __rest(s, e) {
26
- var t = {};
27
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
- t[p] = s[p];
29
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
- t[p[i]] = s[p[i]];
33
- }
34
- return t;
10
+ function _objectWithoutPropertiesLoose(source, excluded) {
11
+ if (source == null) return {};
12
+ var target = {};
13
+ var sourceKeys = Object.keys(source);
14
+ var key, i;
15
+ for (i = 0; i < sourceKeys.length; i++) {
16
+ key = sourceKeys[i];
17
+ if (excluded.indexOf(key) >= 0) continue;
18
+ target[key] = source[key];
19
+ }
20
+ return target;
35
21
  }
36
22
 
37
23
  const Tracker = ({
38
- isFirstPageviewAlreadyTracked
24
+ onRouteChange
39
25
  }) => {
40
26
  const router = useRouter();
41
- const {
42
- page
43
- } = useNinetailed();
44
- const lastFiredPageRef = useRef(isFirstPageviewAlreadyTracked ? 'tracked' : 'none');
27
+ const ninetailed = useNinetailed();
28
+ const lastFiredPageRef = useRef('none');
45
29
  useEffect(() => {
46
30
  logger.debug('Ninetailed Next.js Tracker', 'The useEffect hook to listen for route changes got called. On instantiation the last fired page is:', lastFiredPageRef.current);
47
31
  const handleRouteChange = url => {
@@ -53,7 +37,13 @@ const Tracker = ({
53
37
  });
54
38
  if (!isPageAlreadyTracked) {
55
39
  logger.debug('Ninetailed Next.js Tracker', 'Page is not tracked yet, calling the ninetailed.page function.');
56
- page();
40
+ if (typeof onRouteChange === 'function') {
41
+ onRouteChange({
42
+ isInitialRoute: lastFiredPageRef.current === 'none'
43
+ }, ninetailed);
44
+ } else {
45
+ ninetailed.page();
46
+ }
57
47
  logger.debug('Ninetailed Next.js Tracker', 'Page got tracked, setting the last fired page to the current url.', url);
58
48
  lastFiredPageRef.current = url;
59
49
  }
@@ -68,14 +58,20 @@ const Tracker = ({
68
58
  return null;
69
59
  };
70
60
 
71
- const NinetailedProvider = _a => {
72
- var {
61
+ const _excluded = ["children"],
62
+ _excluded2 = ["onRouteChange"];
63
+ const NinetailedProvider = _ref => {
64
+ let {
73
65
  children
74
- } = _a,
75
- props = __rest(_a, ["children"]);
76
- return jsxs(NinetailedProvider$1, Object.assign({}, props, {
77
- children: [jsx(Tracker, {
78
- isFirstPageviewAlreadyTracked: false
66
+ } = _ref,
67
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
68
+ const {
69
+ onRouteChange
70
+ } = props,
71
+ providerProps = _objectWithoutPropertiesLoose(props, _excluded2);
72
+ return /*#__PURE__*/jsxs(NinetailedProvider$1, Object.assign({}, providerProps, {
73
+ children: [/*#__PURE__*/jsx(Tracker, {
74
+ onRouteChange: onRouteChange
79
75
  }), children]
80
76
  }));
81
77
  };
package/package.json CHANGED
@@ -1,25 +1,29 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js-next",
3
- "version": "7.5.3",
3
+ "version": "7.6.0-beta.2",
4
4
  "description": "Ninetailed SDK for Next.js",
5
5
  "peerDependencies": {
6
6
  "next": ">=9.0.0",
7
7
  "react": ">=16.8.0"
8
8
  },
9
+ "dependencies": {
10
+ "@ninetailed/experience.js-react": "*",
11
+ "@ninetailed/experience.js-plugin-ssr": "*",
12
+ "@ninetailed/experience.js": "*",
13
+ "@ninetailed/experience.js-shared": "*"
14
+ },
9
15
  "license": "MIT",
10
16
  "repository": {
11
17
  "type": "git",
12
18
  "url": "https://github.com/ninetailed-inc/experience.js.git",
13
19
  "directory": "packages/sdks/nextjs"
14
20
  },
15
- "module": "./index.js",
16
- "main": "./index.cjs",
17
- "type": "module",
18
- "types": "./src/index.d.ts",
19
- "dependencies": {
20
- "@ninetailed/experience.js": "7.5.3",
21
- "@ninetailed/experience.js-plugin-ssr": "7.5.1",
22
- "@ninetailed/experience.js-react": "7.5.3",
23
- "@ninetailed/experience.js-shared": "7.5.3"
24
- }
21
+ "keywords": [
22
+ "nextjs",
23
+ "ninetailed",
24
+ "personalization",
25
+ "a/b testing"
26
+ ],
27
+ "module": "./index.esm.js",
28
+ "main": "./index.cjs.js"
25
29
  }
@@ -1,3 +1,6 @@
1
1
  import React from 'react';
2
2
  import { NinetailedProviderProps } from '@ninetailed/experience.js-react';
3
- export declare const NinetailedProvider: React.FC<React.PropsWithChildren<NinetailedProviderProps>>;
3
+ import { OnRouteChange } from './Tracker';
4
+ export declare const NinetailedProvider: React.FC<React.PropsWithChildren<NinetailedProviderProps & {
5
+ onRouteChange?: OnRouteChange;
6
+ }>>;
@@ -1,6 +1,10 @@
1
1
  import React from 'react';
2
+ import { NinetailedInstance } from '@ninetailed/experience.js';
3
+ export type OnRouteChange = (routeInfo: {
4
+ isInitialRoute: boolean;
5
+ }, ninetailed: NinetailedInstance) => void;
2
6
  type TrackerProps = {
3
- isFirstPageviewAlreadyTracked: boolean;
7
+ onRouteChange?: OnRouteChange;
4
8
  };
5
9
  export declare const Tracker: React.FC<React.PropsWithChildren<TrackerProps>>;
6
10
  export {};