gatsby-plugin-rudderstack 3.0.0-beta.1 → 4.0.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/CHANGELOG.md +31 -0
- package/README.md +77 -58
- package/gatsby-ssr.js +16 -32
- package/package.json +25 -23
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [4.0.0](https://github.com/rudderlabs/gatsby-plugin-rudderstack/compare/v3.0.0...v4.0.0) (2024-03-28)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* use js sdk v3 ([#30](https://github.com/rudderlabs/gatsby-plugin-rudderstack/issues/30)) ([3c81fd7](https://github.com/rudderlabs/gatsby-plugin-rudderstack/commit/3c81fd7eefefdf3afe1f8a28fd5a5eff7b6009c6))
|
|
11
|
+
* use JS SDK v3 loading snippet with new useLegacySDK option for v2.x usage ([#26](https://github.com/rudderlabs/gatsby-plugin-rudderstack/issues/26)) ([c05cdbb](https://github.com/rudderlabs/gatsby-plugin-rudderstack/commit/c05cdbb15ef5fb6862d7d9804e980219d7ab6fe3))
|
|
12
|
+
|
|
13
|
+
## [2.0.0](https://github.com/rudderlabs/gatsby-plugin-rudderstack/compare/a2ed4a794130f7a0dd783f42c1107aa44089a45c...v2.0.0) (2022-12-14)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### ⚠ BREAKING CHANGES
|
|
17
|
+
|
|
18
|
+
* modify delayLoad functionality (#17)
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* Added option to use new JS SDK ([#10](https://github.com/rudderlabs/gatsby-plugin-rudderstack/issues/10)) ([a2ed4a7](https://github.com/rudderlabs/gatsby-plugin-rudderstack/commit/a2ed4a794130f7a0dd783f42c1107aa44089a45c))
|
|
23
|
+
* modify delayLoad functionality ([#17](https://github.com/rudderlabs/gatsby-plugin-rudderstack/issues/17)) ([65f176d](https://github.com/rudderlabs/gatsby-plugin-rudderstack/commit/65f176dd8e7fff4749b7142ba16d63519651fe45))
|
|
24
|
+
|
|
25
|
+
## [3.0.0](https://github.com/rudderlabs/gatsby-plugin-rudderstack/compare/v2.0.0...v3.0.0) (2023-12-05)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### ⚠ BREAKING CHANGES
|
|
29
|
+
|
|
30
|
+
* Default JS SDK version is now v3.x, this version comes with [breaking changes](https://www.rudderstack.com/docs/sources/event-streams/sdks/rudderstack-javascript-sdk/v3/#breaking-changes) and [new features](https://www.rudderstack.com/docs/sources/event-streams/sdks/rudderstack-javascript-sdk/v3/#new-features)
|
|
31
|
+
|
|
32
|
+
### Features
|
|
33
|
+
|
|
34
|
+
* use JS SDK v3 loading snippet with new useLegacySDK option for v2.x usage ([#26](https://github.com/rudderlabs/gatsby-plugin-rudderstack/issues/26)) ([c05cdbb](https://github.com/rudderlabs/gatsby-plugin-rudderstack/commit/c05cdbb15ef5fb6862d7d9804e980219d7ab6fe3))
|
|
35
|
+
|
|
5
36
|
## 2.0.0 (2022-12-14)
|
|
6
37
|
|
|
7
38
|
|
package/README.md
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
<p align="center"
|
|
4
|
-
<
|
|
1
|
+
## [](https://github.com/rudderlabs/gatsby-plugin-rudderstack/releases) [](https://sonarcloud.io/summary/new_code?id=rudderlabs_gatsby-plugin-rudderstack) [](https://sonarcloud.io/summary/new_code?id=rudderlabs_gatsby-plugin-rudderstack) [](https://sonarcloud.io/summary/new_code?id=rudderlabs_gatsby-plugin-rudderstack) [](https://sonarcloud.io/summary/new_code?id=rudderlabs_gatsby-plugin-rudderstack) [](https://sonarcloud.io/summary/new_code?id=rudderlabs_gatsby-plugin-rudderstack)
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://rudderstack.com/">
|
|
5
|
+
<img alt="RudderStack" width="512" src="https://raw.githubusercontent.com/rudderlabs/rudder-sdk-js/develop/assets/rs-logo-full-light.jpg">
|
|
6
|
+
</a>
|
|
7
|
+
<br />
|
|
8
|
+
<caption>The Customer Data Platform for Developers</caption>
|
|
9
|
+
</p>
|
|
10
|
+
<p align="center">
|
|
11
|
+
<b>
|
|
12
|
+
<a href="https://rudderstack.com">Website</a>
|
|
13
|
+
·
|
|
14
|
+
<a href="https://rudderstack.com/docs/stream-sources/rudderstack-sdk-integration-guides/rudderstack-javascript-sdk/">Documentation</a>
|
|
15
|
+
·
|
|
16
|
+
<a href="https://rudderstack.com/join-rudderstack-slack-community">Community Slack</a>
|
|
17
|
+
</b>
|
|
18
|
+
</p>
|
|
5
19
|
|
|
6
20
|
# The RudderStack Plugin for Gatsby.
|
|
7
21
|
|
|
@@ -9,11 +23,11 @@ This is a way for you to quickly and easily get RudderStack up and running in yo
|
|
|
9
23
|
|
|
10
24
|
Questions? Please join our [Slack channel](https://resources.rudderstack.com/join-rudderstack-slack) or read about us on [Product Hunt](https://www.producthunt.com/posts/rudderstack).
|
|
11
25
|
|
|
12
|
-
|
|
26
|
+
## Why Use This plugin
|
|
13
27
|
|
|
14
28
|
This plugin makes it easy to integrate your Gatsby website with the RudderStack API and easily track events.
|
|
15
29
|
|
|
16
|
-
|
|
30
|
+
## Key Features
|
|
17
31
|
|
|
18
32
|
- use multiple write keys (one for prod env, another optional one for dev)
|
|
19
33
|
- disable page view tracking (just in case you want to add it later manually)
|
|
@@ -24,9 +38,9 @@ This plugin makes it easy to integrate your Gatsby website with the RudderStack
|
|
|
24
38
|
- NPM: `$ npm install --save gatsby-plugin-rudderstack`
|
|
25
39
|
- YARN: `$ yarn add gatsby-plugin-rudderstack`
|
|
26
40
|
|
|
27
|
-
|
|
41
|
+
## [Setup](https://github.com/rudderlabs/gatsby-plugin-rudderstack/blob/master/README.md#setup)
|
|
28
42
|
|
|
29
|
-
|
|
43
|
+
### [Step 1: Configure Your Gatsby Config File](https://github.com/rudderlabs/gatsby-plugin-rudderstack/blob/master/README.md#step-1-configure-gatsby)
|
|
30
44
|
|
|
31
45
|
In your gatsby-config.js file:
|
|
32
46
|
|
|
@@ -40,7 +54,7 @@ plugins: [
|
|
|
40
54
|
// required; non-empty string
|
|
41
55
|
//NOTE: Do not commit this to git. Process from env.
|
|
42
56
|
prodKey: `RUDDERSTACK_PRODUCTION_WRITE_KEY`,
|
|
43
|
-
|
|
57
|
+
|
|
44
58
|
// if you have a development env for your rudderstack account, paste that key here
|
|
45
59
|
// when process.env.NODE_ENV === 'development'
|
|
46
60
|
// optional; non-empty string
|
|
@@ -98,7 +112,7 @@ plugins: [
|
|
|
98
112
|
// Can be used to override where the SDK should be loaded from. This is useful
|
|
99
113
|
// if you want to serve the SDK from a custom domain other than RudderStack to tackle ad-blockers
|
|
100
114
|
// By default, the plugin will use the latest JS SDK from RudderStack's CDN
|
|
101
|
-
sdkURL: `https://subdomain.yourdomain.com/
|
|
115
|
+
sdkURL: `https://subdomain.yourdomain.com/v3`,
|
|
102
116
|
|
|
103
117
|
// string ('async' or 'defer'); whether to load the RudderStack SDK async or defer. Anything else
|
|
104
118
|
// will load normally.
|
|
@@ -118,7 +132,7 @@ plugins: [
|
|
|
118
132
|
];
|
|
119
133
|
```
|
|
120
134
|
|
|
121
|
-
|
|
135
|
+
### [Step 2: Identify Your Users With the `identify()` Method:](https://github.com/rudderlabs/gatsby-plugin-rudderstack/blob/master/README.md#step-2-identify-your-users-using-the-identify-method)
|
|
122
136
|
|
|
123
137
|
The `identify()` method allows you to link users and their actions to a specific userid.
|
|
124
138
|
|
|
@@ -126,26 +140,31 @@ A sample example of how the `identify()` method works in Gatsby is as shown:
|
|
|
126
140
|
|
|
127
141
|
```javascript
|
|
128
142
|
class CallToAction extends React.Component {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
143
|
+
_handleCallToAction() {
|
|
144
|
+
window.rudderanalytics.identify(
|
|
145
|
+
'12345',
|
|
146
|
+
{
|
|
147
|
+
email: 'name@domain.com',
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
page: {
|
|
151
|
+
path: '/post',
|
|
152
|
+
referrer: 'internal',
|
|
153
|
+
search: '',
|
|
154
|
+
title: 'Post Page',
|
|
155
|
+
url: '',
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
render() {
|
|
162
|
+
return (
|
|
163
|
+
<Link onClick={this._handleCallToAction} to="/write-post">
|
|
164
|
+
Write a Post
|
|
165
|
+
</Link>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
149
168
|
}
|
|
150
169
|
```
|
|
151
170
|
|
|
@@ -153,7 +172,7 @@ In the above example, information such as the user ID, email along with contextu
|
|
|
153
172
|
|
|
154
173
|
> **NOTE**: There is no need to call `identify()` for anonymous visitors to your website. Such visitors are automatically assigned an `anonymousId`.
|
|
155
174
|
|
|
156
|
-
|
|
175
|
+
### [Step 3: Track Your Users’ Actions With the `track()` Method](https://github.com/rudderlabs/rudder-sdk-js/blob/master/README.md#step-3-track-your-users-actions-using-the-track-method)
|
|
157
176
|
|
|
158
177
|
The `track()` method allows you to track any actions that your users might perform.
|
|
159
178
|
|
|
@@ -161,15 +180,15 @@ A sample example of how the `track()` method works is as shown:
|
|
|
161
180
|
|
|
162
181
|
```javascript
|
|
163
182
|
window.rudderanalytics.track(
|
|
164
|
-
|
|
183
|
+
'test track event GA3',
|
|
165
184
|
{
|
|
166
185
|
revenue: 30,
|
|
167
|
-
currency:
|
|
186
|
+
currency: 'USD',
|
|
168
187
|
user_actual_id: 12345,
|
|
169
188
|
},
|
|
170
189
|
() => {
|
|
171
|
-
console.log(
|
|
172
|
-
}
|
|
190
|
+
console.log('in track call');
|
|
191
|
+
},
|
|
173
192
|
);
|
|
174
193
|
```
|
|
175
194
|
|
|
@@ -181,19 +200,19 @@ You can use this method to track various other success metrics for your website,
|
|
|
181
200
|
|
|
182
201
|
```javascript
|
|
183
202
|
window.rudderanalytics.track(
|
|
184
|
-
|
|
203
|
+
'test track event GA3',
|
|
185
204
|
{
|
|
186
205
|
revenue: 30,
|
|
187
|
-
currency:
|
|
206
|
+
currency: 'USD',
|
|
188
207
|
user_actual_id: 12345,
|
|
189
208
|
},
|
|
190
209
|
() => {
|
|
191
|
-
console.log(
|
|
192
|
-
}
|
|
210
|
+
console.log('in track call');
|
|
211
|
+
},
|
|
193
212
|
);
|
|
194
213
|
```
|
|
195
214
|
|
|
196
|
-
|
|
215
|
+
#### Track Pageviews
|
|
197
216
|
|
|
198
217
|
**If you want to track pageviews automatically,** set `trackPage` to `true` in your `gatsby-config.js` file. What we mean by _"automatically"_ is that whenever there is a route change, we leverage Gatsby's `onRouteUpdate` API in the `gatsby-browser.js` file ([link](https://www.gatsbyjs.org/docs/browser-apis/#onRouteUpdate)) to invoke `window.rudderanalytics.page()` on each route change. But if you want to pass in properties along with the pageview call (ie, it's common to see folks pass in some user or account data with each page call), then you'll have to set `trackPage: false` and call it yourself in your `gatsby-browser.js` file, like this:
|
|
199
218
|
|
|
@@ -208,7 +227,7 @@ Note: The above code snippet might not give the best results all the time as it
|
|
|
208
227
|
|
|
209
228
|
You’ve now successfully installed `rudder-analytics.js` tracking. You can enable and use any event destination to send your event data via RudderStack, in no time at all!
|
|
210
229
|
|
|
211
|
-
|
|
230
|
+
### [Step 4: Check Ready State](https://github.com/rudderlabs/rudder-sdk-js/blob/master/README.md#step-4-check-ready-state)
|
|
212
231
|
|
|
213
232
|
**There are cases when you may want to tap into the features provide by end destination SDKs to enhance tracking and other functionalities.** RudderStack's JavaScript SDK exposes a `ready` API with a `callback` parameter, that fires when the SDK is done initializing itself and other third-party native SDK destinations.
|
|
214
233
|
|
|
@@ -216,29 +235,29 @@ For example:
|
|
|
216
235
|
|
|
217
236
|
```javascript
|
|
218
237
|
window.rudderanalytics.ready(() => {
|
|
219
|
-
console.log(
|
|
238
|
+
console.log('we are all set!!!');
|
|
220
239
|
});
|
|
221
240
|
```
|
|
222
241
|
|
|
223
242
|
| **For detailed technical documentation and troubleshooting guide on the RudderStack’s JavaScript SDK, check out our [docs](https://docs.rudderlabs.com/sdk-integration-guide/getting-started-with-javascript-sdk).** |
|
|
224
243
|
| :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
225
244
|
|
|
226
|
-
|
|
245
|
+
## [Querystring API](https://github.com/rudderlabs/rudder-sdk-js/blob/master/README.md#querystring-api)
|
|
227
246
|
|
|
228
247
|
RudderStack's Querystring API allows you to trigger `track`, `identify` calls using query parameters. If you pass the following parameters in the URL, then it will trigger the corresponding SDK API call.
|
|
229
248
|
|
|
230
249
|
For example:
|
|
231
250
|
|
|
232
251
|
```html
|
|
233
|
-
|
|
252
|
+
https://hostname.com/?ajs_uid=12345&ajs_event=test%20event&ajs_aid=abcde&ajs_prop_testProp=prop1&ajs_trait_name=Firstname+Lastname
|
|
234
253
|
```
|
|
235
254
|
|
|
236
255
|
For the above URL, the below SDK calls will be triggered:
|
|
237
256
|
|
|
238
257
|
```javascript
|
|
239
|
-
rudderanalytics.identify(
|
|
240
|
-
rudderanalytics.track(
|
|
241
|
-
rudderanalytics.setAnonymousId(
|
|
258
|
+
rudderanalytics.identify('12345', { name: 'Firstname Lastname' });
|
|
259
|
+
rudderanalytics.track('test event', { testProp: 'prop1' });
|
|
260
|
+
rudderanalytics.setAnonymousId('abcde');
|
|
242
261
|
```
|
|
243
262
|
|
|
244
263
|
You may use the below parameters as querystring parameter and trigger the corresponding call.
|
|
@@ -253,7 +272,7 @@ You may use the below parameters as querystring parameter and trigger the corres
|
|
|
253
272
|
|
|
254
273
|
`ajs_trait_<trait>` : If `ajs_uid` is provided as querysting, value of this parameter will populate the `traits` of the `identify` call made.
|
|
255
274
|
|
|
256
|
-
# [](https://github.com/rudderlabs/rudder-sdk-js/blob/master/README.md#adding-callbacks-to-standard-methods)
|
|
275
|
+
# [Adding Callbacks to Standard Methods](https://github.com/rudderlabs/rudder-sdk-js/blob/master/README.md#adding-callbacks-to-standard-methods)
|
|
257
276
|
|
|
258
277
|
You can also define callbacks to the common methods of the `rudderanalytics` object.
|
|
259
278
|
|
|
@@ -264,9 +283,9 @@ For example, you can load the rudderanalytics with callbacks in your Gatsby brow
|
|
|
264
283
|
```javascript
|
|
265
284
|
window.rudderanalytics.syncPixelCallback = (obj) => {
|
|
266
285
|
window.rudderanalytics.track(
|
|
267
|
-
|
|
286
|
+
'sync lotame',
|
|
268
287
|
{ destination: obj.destination },
|
|
269
|
-
{ integrations: { All: false, S3: true } }
|
|
288
|
+
{ integrations: { All: false, S3: true } },
|
|
270
289
|
);
|
|
271
290
|
};
|
|
272
291
|
```
|
|
@@ -282,21 +301,21 @@ The callback can be supplied in options parameter like below as well:
|
|
|
282
301
|
rudderanalytics.load(YOUR_WRITE_KEY, DATA_PLANE_URL, {
|
|
283
302
|
clientSuppliedCallbacks: {
|
|
284
303
|
syncPixelCallback: () => {
|
|
285
|
-
console.log(
|
|
304
|
+
console.log('sync done!');
|
|
286
305
|
},
|
|
287
306
|
},
|
|
288
307
|
});
|
|
289
308
|
```
|
|
290
309
|
|
|
291
|
-
|
|
310
|
+
## License
|
|
292
311
|
|
|
293
312
|
RudderStack **gatsby-plugin-rudderstack** is released under the [AGPLv3 License][agplv3_license].
|
|
294
313
|
|
|
295
|
-
|
|
314
|
+
## Contribute
|
|
296
315
|
|
|
297
316
|
We would love to see you contribute to RudderStack. Get more information on how to contribute [here](CONTRIBUTING.md).
|
|
298
317
|
|
|
299
|
-
|
|
318
|
+
## Follow Us
|
|
300
319
|
|
|
301
320
|
- [RudderStack Blog][rudderstack-blog]
|
|
302
321
|
- [Slack][slack]
|
|
@@ -308,10 +327,10 @@ We would love to see you contribute to RudderStack. Get more information on how
|
|
|
308
327
|
- [HackerNews][hackernews]
|
|
309
328
|
- [Product Hunt][producthunt]
|
|
310
329
|
|
|
311
|
-
|
|
330
|
+
## :clap: Our Supporters
|
|
312
331
|
|
|
313
|
-
[](https://github.com/rudderlabs/gatsby-plugin-rudderstack/stargazers)
|
|
333
|
+
[](https://github.com/rudderlabs/gatsby-plugin-rudderstack/network/members)
|
|
315
334
|
|
|
316
335
|
<!----variables---->
|
|
317
336
|
|
package/gatsby-ssr.js
CHANGED
|
@@ -1,60 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
function
|
|
5
|
-
function ownKeys(
|
|
6
|
-
function _objectSpread(
|
|
7
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
3
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
9
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
10
|
exports.onRenderBody = function (_ref, pluginOptions) {
|
|
9
11
|
var setHeadComponents = _ref.setHeadComponents;
|
|
10
12
|
var prodKey = pluginOptions.prodKey,
|
|
11
13
|
devKey = pluginOptions.devKey,
|
|
12
14
|
_pluginOptions$dataPl = pluginOptions.dataPlaneUrl,
|
|
13
|
-
dataPlaneUrl = _pluginOptions$dataPl === void 0 ?
|
|
15
|
+
dataPlaneUrl = _pluginOptions$dataPl === void 0 ? 'https://hosted.rudderlabs.com' : _pluginOptions$dataPl,
|
|
14
16
|
controlPlaneUrl = pluginOptions.controlPlaneUrl,
|
|
15
17
|
delayLoad = pluginOptions.delayLoad,
|
|
16
18
|
delayLoadTime = pluginOptions.delayLoadTime,
|
|
17
19
|
manualLoad = pluginOptions.manualLoad,
|
|
18
20
|
loadType = pluginOptions.loadType,
|
|
19
21
|
_pluginOptions$sdkURL = pluginOptions.sdkURL,
|
|
20
|
-
sdkURL = _pluginOptions$sdkURL === void 0 ?
|
|
22
|
+
sdkURL = _pluginOptions$sdkURL === void 0 ? 'https://cdn.rudderlabs.com/v3' : _pluginOptions$sdkURL,
|
|
21
23
|
_pluginOptions$loadOp = pluginOptions.loadOptions,
|
|
22
|
-
loadOptions = _pluginOptions$loadOp === void 0 ? {} : _pluginOptions$loadOp
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (devKey && devKey.length < 10) console.error("If present, your RudderStack devKey must be at least 10 char in length.");
|
|
28
|
-
|
|
29
|
-
var writeKey = process.env.NODE_ENV === "production" ? prodKey : devKey;
|
|
30
|
-
|
|
24
|
+
loadOptions = _pluginOptions$loadOp === void 0 ? {} : _pluginOptions$loadOp;
|
|
25
|
+
if (!prodKey || prodKey.length < 10) console.error('Your RudderStack prodKey must be at least 10 char in length.');
|
|
26
|
+
if (devKey && devKey.length < 10) console.error('If present, your RudderStack devKey must be at least 10 char in length.');
|
|
27
|
+
var writeKey = process.env.NODE_ENV === 'production' ? prodKey : devKey;
|
|
31
28
|
var finalLoadOptions = _objectSpread(_objectSpread({}, loadOptions), {}, {
|
|
32
29
|
configUrl: controlPlaneUrl || loadOptions.configUrl
|
|
33
30
|
});
|
|
34
31
|
var loadConfig = "'".concat(writeKey, "', '").concat(dataPlaneUrl, "', ").concat(JSON.stringify(finalLoadOptions));
|
|
35
|
-
var snippet = "var sdkBaseUrl
|
|
36
|
-
if (useLegacySDK) {
|
|
37
|
-
var scriptTagStr = "var s = document.createElement(\"script\");\n s.type = \"text/javascript\";\n s.src = \"".concat(sdkURL, "\";");
|
|
38
|
-
if (loadType === "async") {
|
|
39
|
-
scriptTagStr += "s.async = true;";
|
|
40
|
-
} else if (loadType === "defer") {
|
|
41
|
-
scriptTagStr += "s.defer = true;";
|
|
42
|
-
}
|
|
43
|
-
scriptTagStr += "document.head.appendChild(s);";
|
|
44
|
-
snippet = "rudderanalytics=window.rudderanalytics=[];for(var methods=[\"load\",\"page\",\"track\",\"identify\",\"alias\",\"group\",\"ready\",\"reset\",\"getAnonymousId\",\"setAnonymousId\"],i=0;i<methods.length;i++){var method=methods[i];rudderanalytics[method]=function(a){return function(){rudderanalytics.push([a].concat(Array.prototype.slice.call(arguments)))}}(method)}\n ".concat(scriptTagStr);
|
|
45
|
-
}
|
|
32
|
+
var snippet = "!function(){\"use strict\";window.RudderSnippetVersion=\"3.0.3\";var sdkBaseUrl=".concat(sdkURL, ";var sdkName=\"rsa.min.js\";var asyncScript=").concat(loadType === 'async', ";var deferScript=").concat(loadType === 'defer', ";window.rudderAnalyticsBuildType=\"legacy\",window.rudderanalytics=[]\n ;var e=[\"setDefaultInstanceKey\",\"load\",\"ready\",\"page\",\"track\",\"identify\",\"alias\",\"group\",\"reset\",\"setAnonymousId\",\"startSession\",\"endSession\",\"consent\"]\n ;for(var n=0;n<e.length;n++){var t=e[n];window.rudderanalytics[t]=function(e){return function(){\n window.rudderanalytics.push([e].concat(Array.prototype.slice.call(arguments)))}}(t)}try{\n new Function('return import(\"\")'),window.rudderAnalyticsBuildType=\"modern\"}catch(a){}\n if(window.rudderAnalyticsMount=function(){\n \"undefined\"==typeof globalThis&&(Object.defineProperty(Object.prototype,\"__globalThis_magic__\",{get:function get(){\n return this},configurable:true}),__globalThis_magic__.globalThis=__globalThis_magic__,\n delete Object.prototype.__globalThis_magic__);var e=document.createElement(\"script\")\n ;e.src=\"\".concat(sdkBaseUrl,\"/\").concat(window.rudderAnalyticsBuildType,\"/\").concat(sdkName);if(asyncScript){e.async=true};if(deferScript){e.defer=true};document.head?document.head.appendChild(e):document.body.appendChild(e)\n },\"undefined\"==typeof Promise||\"undefined\"==typeof globalThis){var d=document.createElement(\"script\")\n ;d.src=\"https://polyfill-fastly.io/v3/polyfill.min.js?version=3.111.0&features=Symbol%2CPromise&callback=rudderAnalyticsMount\",\n d.async=asyncScript,document.head?document.head.appendChild(d):document.body.appendChild(d)}else{\n window.rudderAnalyticsMount()}}();");
|
|
46
33
|
var instantLoader = "".concat(snippet).concat(manualLoad ? "" : "window.rudderanalytics.load(".concat(loadConfig, ")"), ";");
|
|
47
34
|
var delayedLoader = "\n window.rudderSnippetLoaded = false;\n window.rudderSnippetLoading = false;\n window.rudderSnippetLoadedCallback = undefined;\n window.rudderSnippetLoader = function (callback) {\n if (!window.rudderSnippetLoaded && !window.rudderSnippetLoading) {\n window.rudderSnippetLoading = true;\n function loader() {\n ".concat(snippet, "\n window.rudderanalytics.load(").concat(loadConfig, ");\n window.rudderSnippetLoading = false;\n window.rudderSnippetLoaded = true;\n if (callback) { callback(); }\n if (window.rudderSnippetLoadedCallback) {\n window.rudderSnippetLoadedCallback();\n window.rudderSnippetLoadedCallback = undefined;\n }\n };\n\n \"requestIdleCallback\" in window\n ? requestIdleCallback(function () { loader(); })\n : loader();\n }\n }\n window.addEventListener('scroll',function () {window.rudderSnippetLoader()}, { once: true });\n setTimeout(\n function () {\n \"requestIdleCallback\" in window\n ? requestIdleCallback(function () { window.rudderSnippetLoader(); })\n : window.rudderSnippetLoader();\n },\n ").concat(delayLoadTime, " || 1000\n );\n ");
|
|
48
|
-
|
|
49
35
|
var snippetToUse = "".concat(delayLoad && !manualLoad ? delayedLoader : instantLoader);
|
|
50
|
-
|
|
51
36
|
if (writeKey) {
|
|
52
|
-
var tags = [
|
|
53
|
-
key: "plugin-rudderstack",
|
|
37
|
+
var tags = [(0, _jsxRuntime.jsx)("script", {
|
|
54
38
|
dangerouslySetInnerHTML: {
|
|
55
39
|
__html: snippetToUse
|
|
56
40
|
}
|
|
57
|
-
})];
|
|
41
|
+
}, "plugin-rudderstack")];
|
|
58
42
|
setHeadComponents(tags);
|
|
59
43
|
}
|
|
60
44
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatsby-plugin-rudderstack",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Event tracking with RudderStack in your Gatsby frontend.",
|
|
5
5
|
"main": "gatsby-ssr.js",
|
|
6
6
|
"scripts": {
|
|
@@ -40,31 +40,32 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://github.com/rudderlabs/gatsby-plugin-rudderstack#readme",
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@babel/cli": "
|
|
44
|
-
"@babel/core": "
|
|
45
|
-
"@babel/eslint-parser": "7.
|
|
46
|
-
"@babel/plugin-proposal-object-rest-spread": "
|
|
47
|
-
"@babel/preset-env": "
|
|
48
|
-
"@babel/preset-react": "
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
43
|
+
"@babel/cli": "7.23.4",
|
|
44
|
+
"@babel/core": "7.23.5",
|
|
45
|
+
"@babel/eslint-parser": "7.23.3",
|
|
46
|
+
"@babel/plugin-proposal-object-rest-spread": "7.20.7",
|
|
47
|
+
"@babel/preset-env": "7.23.5",
|
|
48
|
+
"@babel/preset-react": "7.23.3",
|
|
49
|
+
"@commitlint/config-conventional": "18.4.3",
|
|
50
|
+
"@digitalroute/cz-conventional-changelog-for-jira": "8.0.1",
|
|
51
|
+
"commitizen": "4.3.0",
|
|
52
|
+
"commitlint": "18.4.3",
|
|
53
|
+
"conventional-changelog-cli": "4.1.0",
|
|
52
54
|
"conventional-github-releaser": "3.1.5",
|
|
53
|
-
"
|
|
54
|
-
"@digitalroute/cz-conventional-changelog-for-jira": "7.4.2",
|
|
55
|
-
"eslint": "8.28.0",
|
|
55
|
+
"eslint": "8.55.0",
|
|
56
56
|
"eslint-config-airbnb": "19.0.4",
|
|
57
57
|
"eslint-config-airbnb-base": "15.0.0",
|
|
58
|
-
"eslint-config-prettier": "
|
|
59
|
-
"eslint-plugin-compat": "4.0
|
|
60
|
-
"eslint-plugin-import": "2.
|
|
61
|
-
"eslint-plugin-sonarjs": "0.
|
|
62
|
-
"eslint-plugin-unicorn": "
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
58
|
+
"eslint-config-prettier": "9.1.0",
|
|
59
|
+
"eslint-plugin-compat": "4.2.0",
|
|
60
|
+
"eslint-plugin-import": "2.29.0",
|
|
61
|
+
"eslint-plugin-sonarjs": "0.23.0",
|
|
62
|
+
"eslint-plugin-unicorn": "49.0.0",
|
|
63
|
+
"git-cz": "^4.9.0",
|
|
64
|
+
"husky": "8.0.3",
|
|
65
|
+
"jscpd": "3.5.10",
|
|
66
|
+
"lint-staged": "15.2.0",
|
|
67
|
+
"madge": "6.1.0",
|
|
68
|
+
"prettier": "3.1.0",
|
|
68
69
|
"standard-version": "9.5.0"
|
|
69
70
|
},
|
|
70
71
|
"eslintConfig": {
|
|
@@ -87,6 +88,7 @@
|
|
|
87
88
|
},
|
|
88
89
|
"overrides": {
|
|
89
90
|
"dot-prop": "5.3.0",
|
|
91
|
+
"http-cache-semantics": "4.1.1",
|
|
90
92
|
"semver-regex": "3.1.4",
|
|
91
93
|
"trim-newlines": "3.0.1"
|
|
92
94
|
},
|