@ninetailed/experience.js-gatsby 1.7.0-beta.0

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/README.md ADDED
@@ -0,0 +1,166 @@
1
+ # @ninetailed/experience.js-gatsby
2
+
3
+ Add dynamic content personalization to Gatbsy without performance trade-offs or complex integrations.
4
+
5
+ `@ninetailed/experience.js-gatsby` is a React component specially designed to work seamlessly with
6
+ Gatsby and Ninetailed.
7
+
8
+ **[Demo](https://demo.ninetailed.io/saas)**
9
+
10
+ ## Table of Contents
11
+
12
+ - [Ninetailed Platform](#ninetailed-platform)
13
+ - [Install](#install)
14
+ - [Gatsby](#gatsby)
15
+ - [Gatsby and Contentful](#gatsby-and-contentful)
16
+ - [How to use](#how-to-use)
17
+ - [Personalizing Components](#personalizing-components)
18
+ - [Personalize Component](#personalize-component)
19
+ - [Inline Personalization](#inline-personalization)
20
+ - [Contentful Richtext](#contentful-richtext)
21
+ - [Additional Documentation](#additional-documentation)
22
+
23
+ ## Ninetailed Platform
24
+
25
+ Ninetailed is an api-first optimization platform designed for the modern web. It is a headless personalization solution for frameworks like React or Gatsby JS and headless CMS like Contentful. The **[Ninetailed](https://ninetailed.io/)** platform includes:
26
+
27
+ - Real-time personalization API and customer data hub (CDP).
28
+ - Plugins and SDKs for easy integration with major frameworks like Gatsby.
29
+ - CMS integrations to enable content creators easily create personalized content and define audiences.
30
+ - Integration with analytics tools like Google Analytics and Mixpanel.
31
+ - Optional edge side rendering for maximum web performance.
32
+
33
+ ## Install
34
+
35
+ ### Gatsby
36
+
37
+ `npm install @ninetailed/experience.js-gatsby`
38
+
39
+ Install the `@ninetailed/experience.js-gatsby` modules via npm or yarn.
40
+
41
+ **Install module via npm**
42
+
43
+ ```shell
44
+ npm install @ninetailed/experience.js-gatsby
45
+ ```
46
+
47
+ **Install module via yarn**
48
+
49
+ ```shell
50
+ yarn add @ninetailed/experience.js-gatsby
51
+ ```
52
+
53
+ ## How to use
54
+
55
+ Add the plugin to the plugins array in your gatsby-config.js and your API Key.
56
+
57
+ ```js
58
+ plugins: [
59
+ ...your other gatsby plugins
60
+ {
61
+ resolve: `gatsby-plugin-ninetailed`,
62
+ options: {
63
+ clientId: 'your api key'
64
+ }
65
+ }
66
+ ]
67
+ ```
68
+
69
+ > Your API Key can be found in the Contentful app configuration.
70
+
71
+ By using the gatsby plugin there's no need to configure the `NinetailedProvuder` as described in the React tutorial, as this is done by the plugin.
72
+
73
+ The plugin automatically tracks Pageviews on route change, please do not track it on your own as you would duplicate events.
74
+
75
+ ## Personalizing Components
76
+
77
+ ### Personalize Component
78
+
79
+ To make personalizing your components as seamless as possible Ninetailed provides a `<Personalize />` component which wraps the component you'd like to personalize. It automatically detects the properties needed from the wrapped component and also applies a `variants` property.
80
+
81
+ ```TypeScript
82
+ import React from 'react';
83
+ import { Personalize } from '@ninetailed/experience.js-gatsby';
84
+
85
+ type HeadlineProps = {
86
+ text: string;
87
+ }
88
+
89
+ const Headline: React.FC<HeadlineProps> = ({ text }) => {
90
+ return <h1>{text}</h1>
91
+ };
92
+
93
+ export const Page = () => {
94
+ // These variants normally come from your CMS
95
+ // You can use our Contentful App for this
96
+ const variants = [
97
+ {
98
+ text: "We build super nice websites for enterprise companies!",
99
+ audience: "enterprise-audience-id" // variants have a audience id
100
+ }
101
+ ]
102
+
103
+ return (<Personalize
104
+ component={Headline}
105
+ variants={variants}
106
+ text="We build websites for everbody" // this is the baseline for user which are not in a audience.
107
+ />);
108
+ };
109
+ ```
110
+
111
+ ### Inline Personalization
112
+
113
+ Using the visitor's and the useProfile hook makes it very easy to use inline personalization. For advanced cases like contentful Richtext we also provide a SDK - simply have a look at the gatsby section.
114
+
115
+ ```TypeScript
116
+ import React, { useState, useEffect } from 'react';
117
+ import { useProfile } from '@ninetailed/experience.js-gatsby';
118
+
119
+ const Greeting = () => {
120
+ const [loading, profile, error] = useProfile();
121
+
122
+ if (loading) {
123
+ return <h2>Hey 👋, how is your day?</h2>
124
+ }
125
+
126
+ return <h2>Hey {profile.traits.firstname}👋, how is your day?</h2>
127
+ };
128
+ ```
129
+
130
+ ## Richtext
131
+
132
+ The Ninetailed Contentful App gives your content creators the option to use inline personalization in richtext fields. This is done by adding embeded entries into the text. To make the personalization working on the developer end the `@ninetailed/experience.js-gatsby` SDK provides functions which render the personalized entry.
133
+
134
+ ```TypeScript
135
+ import React from 'react';
136
+ import {
137
+ renderRichText,
138
+ RenderRichTextData,
139
+ ContentfulRichTextGatsbyReference,
140
+ } from 'gatsby-source-contentful/rich-text';
141
+ import { MergeTag } from '@ninetailed/experience.js-gatsby';
142
+
143
+ const options = {
144
+ renderNode: {
145
+ [INLINES.EMBEDDED_ENTRY]: (node) => {
146
+ const id = node.data.target.id;
147
+ if (node.data.target.__typename === "ContentfulNtMergeTag" && id) {
148
+ return <MergeTag id={mergeTag.id} />;
149
+ }
150
+ return <>{`${node.nodeType} ${id}`}</>;
151
+ }
152
+ },
153
+ };
154
+
155
+ type HeadlineProps = {
156
+ text: RenderRichTextData<ContentfulRichTextGatsbyReference>;
157
+ };
158
+
159
+ const Headline: React.FC<HeadlineProps> = ({ text }) => {
160
+ return <h1>{renderRichText(text, options)}</h1>
161
+ }
162
+ ```
163
+
164
+ ## Additional Documentation
165
+
166
+ **[Documentation](https://docs.ninetailed.io/)**
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wrapRootElement = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = (0, tslib_1.__importDefault)(require("react"));
6
+ const experience_js_react_1 = require("@ninetailed/experience.js-react");
7
+ const Tracker_1 = require("./src/lib/Tracker");
8
+ const WrapRootElement = (_a) => {
9
+ var { children } = _a, options = (0, tslib_1.__rest)(_a, ["children"]);
10
+ return (react_1.default.createElement(experience_js_react_1.NinetailedProvider, Object.assign({}, options),
11
+ react_1.default.createElement(Tracker_1.Tracker, null),
12
+ children));
13
+ };
14
+ const wrapRootElement = (args, options) => {
15
+ const { element } = args;
16
+ return react_1.default.createElement(WrapRootElement, Object.assign({}, options), element);
17
+ };
18
+ exports.wrapRootElement = wrapRootElement;
19
+ //# sourceMappingURL=gatsby-browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gatsby-browser.js","sourceRoot":"","sources":["../../../packages/gatsby/gatsby-browser.tsx"],"names":[],"mappings":";;;;AAAA,+DAAuC;AAEvC,yEAAqE;AAErE,+CAA4C;AAG5C,MAAM,eAAe,GAA4B,CAAC,EAGjD,EAAE,EAAE;QAH6C,EAChD,QAAQ,OAET,EADI,OAAO,2BAFsC,YAGjD,CADW;IAEV,OAAO,CACL,8BAAC,wCAAkB,oBAAK,OAAO;QAC7B,8BAAC,iBAAO,OAAG;QACV,QAAQ,CACU,CACtB,CAAC;AACJ,CAAC,CAAC;AAEK,MAAM,eAAe,GAAG,CAC7B,IAAgC,EAChC,OAAsB,EACtB,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEzB,OAAO,8BAAC,eAAe,oBAAK,OAAO,GAAG,OAAO,CAAmB,CAAC;AACnE,CAAC,CAAC;AAPW,QAAA,eAAe,mBAO1B"}
package/gatsby-node.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pluginOptionsSchema = void 0;
4
+ const pluginOptionsSchema = ({ Joi, }) => {
5
+ return Joi.object({
6
+ clientId: Joi.string()
7
+ .required()
8
+ .description('Your organizations\' client id.')
9
+ .messages({
10
+ 'any.required': '"clientId" needs to be specified. Get your clientId from the dashboard.',
11
+ })
12
+ });
13
+ };
14
+ exports.pluginOptionsSchema = pluginOptionsSchema;
15
+ //# sourceMappingURL=gatsby-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gatsby-node.js","sourceRoot":"","sources":["../../../packages/gatsby/gatsby-node.tsx"],"names":[],"mappings":";;;AAGO,MAAM,mBAAmB,GAAG,CAAC,EAClC,GAAG,GACqB,EAAqB,EAAE;IAC/C,OAAO,GAAG,CAAC,MAAM,CAAC;QAChB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE;aACnB,QAAQ,EAAE;aACV,WAAW,CAAC,iCAAiC,CAAC;aAC9C,QAAQ,CAAC;YACR,cAAc,EACZ,yEAAyE;SAC5E,CAAC;KACL,CAAC,CAAC;AACL,CAAC,CAAC;AAZW,QAAA,mBAAmB,uBAY9B"}
package/gatsby-ssr.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wrapRootElement = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = (0, tslib_1.__importDefault)(require("react"));
6
+ const experience_js_react_1 = require("@ninetailed/experience.js-react");
7
+ const wrapRootElement = (args, options) => {
8
+ const { element } = args;
9
+ return react_1.default.createElement(experience_js_react_1.NinetailedProvider, Object.assign({}, options), element);
10
+ };
11
+ exports.wrapRootElement = wrapRootElement;
12
+ //# sourceMappingURL=gatsby-ssr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gatsby-ssr.js","sourceRoot":"","sources":["../../../packages/gatsby/gatsby-ssr.tsx"],"names":[],"mappings":";;;;AAAA,+DAA0B;AAE1B,yEAAqE;AAI9D,MAAM,eAAe,GAAG,CAC7B,IAA6B,EAC7B,OAAsB,EACtB,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEzB,OAAO,8BAAC,wCAAkB,oBAAK,OAAO,GAAG,OAAO,CAAsB,CAAC;AACzE,CAAC,CAAC;AAPW,QAAA,eAAe,mBAO1B"}
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ // This needs to exist, so the gatsby plugin build process works.
2
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/gatsby/index.js"],"names":[],"mappings":"AAAA,iEAAiE"}
package/jest.config.js ADDED
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ displayName: 'experience-sdk-gatsby',
3
+ preset: '../../jest.preset.js',
4
+ transform: {
5
+ '^.+\\.[tj]sx?$': [
6
+ 'babel-jest',
7
+ { cwd: __dirname, configFile: './babel-jest.config.json' },
8
+ ],
9
+ },
10
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
11
+ coverageDirectory: '../../coverage/packages/gatsby',
12
+ };
13
+ //# sourceMappingURL=jest.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jest.config.js","sourceRoot":"","sources":["../../../packages/gatsby/jest.config.js"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,GAAG;IACf,WAAW,EAAE,uBAAuB;IACpC,MAAM,EAAE,sBAAsB;IAC9B,SAAS,EAAE;QACT,gBAAgB,EAAE;YAChB,YAAY;YACZ,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,0BAA0B,EAAE;SAC3D;KACF;IACD,oBAAoB,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC;IAChD,iBAAiB,EAAE,gCAAgC;CACpD,CAAC"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@ninetailed/experience.js-gatsby",
3
+ "version": "1.7.0-beta.0",
4
+ "main": "index.js",
5
+ "keywords": [
6
+ "gatsby",
7
+ "gatsby-plugin",
8
+ "ninetailed",
9
+ "personalization",
10
+ "a/b testing"
11
+ ],
12
+ "description": "Ninetailed Gatsby Plugin for dynamic content, personalization and a/b testing.",
13
+ "homepage": "https://docs.ninetailed.io/frameworks/gatsby",
14
+ "peerDependencies": {
15
+ "react": ">=16.8.0",
16
+ "gatsby": ">=2.27.4"
17
+ },
18
+ "typings": "./src/index.d.ts",
19
+ "dependencies": {
20
+ "@ninetailed/experience.js-react": "1.7.0-beta.0",
21
+ "@analytics/google-analytics": "^0.5.3",
22
+ "lodash": "^4.17.21",
23
+ "@ninetailed/experience.js": "1.7.0-beta.0",
24
+ "analytics": "^0.8.0",
25
+ "@ninetailed/experience.js-shared": "1.7.0-beta.0",
26
+ "uuid": "^8.3.2",
27
+ "ts-toolbelt": "^9.6.0",
28
+ "locale-enum": "^1.1.1",
29
+ "i18n-iso-countries": "^7.3.0",
30
+ "react-intersection-observer": "^8.33.1"
31
+ }
32
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=plugin-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-options.js","sourceRoot":"","sources":["../../../packages/gatsby/plugin-options.ts"],"names":[],"mappings":""}
package/src/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ require("../gatsby-browser");
5
+ require("../gatsby-node");
6
+ require("../gatsby-ssr");
7
+ (0, tslib_1.__exportStar)(require("./lib/Tracker"), exports);
8
+ (0, tslib_1.__exportStar)(require("@ninetailed/experience.js-react"), exports);
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/gatsby/src/index.ts"],"names":[],"mappings":";;;AAAA,6BAA2B;AAC3B,0BAAwB;AACxB,yBAAuB;AAEvB,6DAA8B;AAC9B,+EAAgD"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Tracker = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = (0, tslib_1.__importDefault)(require("react"));
6
+ const react_2 = require("react");
7
+ const router_1 = require("@reach/router");
8
+ const experience_js_react_1 = require("@ninetailed/experience.js-react");
9
+ const usePrevious = (value) => {
10
+ const ref = (0, react_2.useRef)();
11
+ (0, react_2.useEffect)(() => {
12
+ ref.current = value;
13
+ });
14
+ return ref.current;
15
+ };
16
+ const Executor = ({ location }) => {
17
+ const { page } = (0, experience_js_react_1.useNinetailed)();
18
+ const previousPathname = usePrevious(location);
19
+ const pathname = location.pathname;
20
+ (0, react_2.useEffect)(() => {
21
+ if (pathname !== previousPathname) {
22
+ page();
23
+ }
24
+ }, [pathname, previousPathname, page]);
25
+ return null;
26
+ };
27
+ const Tracker = () => {
28
+ return react_1.default.createElement(router_1.Location, null, (location) => react_1.default.createElement(Executor, Object.assign({}, location)));
29
+ };
30
+ exports.Tracker = Tracker;
31
+ //# sourceMappingURL=Tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tracker.js","sourceRoot":"","sources":["../../../../../../packages/gatsby/src/lib/Tracker/Tracker.tsx"],"names":[],"mappings":";;;;AAAA,+DAA0B;AAC1B,iCAA0C;AAC1C,0CAA0D;AAE1D,yEAAgE;AAEhE,MAAM,WAAW,GAAG,CAAC,KAAU,EAAE,EAAE;IACjC,MAAM,GAAG,GAAG,IAAA,cAAM,GAAE,CAAC;IACrB,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IACtB,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC,OAAO,CAAC;AACrB,CAAC,CAAC;AAEF,MAAM,QAAQ,GAA8B,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC3D,MAAM,EAAE,IAAI,EAAE,GAAG,IAAA,mCAAa,GAAE,CAAC;IACjC,MAAM,gBAAgB,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;IAEnC,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,QAAQ,KAAK,gBAAgB,EAAE;YACjC,IAAI,EAAE,CAAC;SACR;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC,CAAC;IAEvC,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEK,MAAM,OAAO,GAAG,GAAG,EAAE;IAC1B,OAAO,8BAAC,iBAAQ,QAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,8BAAC,QAAQ,oBAAK,QAAQ,EAAI,CAAY,CAAC;AACzE,CAAC,CAAC;AAFW,QAAA,OAAO,WAElB"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./Tracker"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/gatsby/src/lib/Tracker/index.ts"],"names":[],"mappings":";;;AAAA,yDAA0B"}