gatsby-plugin-rudderstack 3.0.0 → 4.0.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/CHANGELOG.md +15 -0
- package/README.md +0 -4
- package/gatsby-ssr.js +2 -13
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
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.1](https://github.com/rudderlabs/gatsby-plugin-rudderstack/compare/v4.0.0...v4.0.1) (2024-03-29)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
* fix: loading snippet ([766f805]https://github.com/rudderlabs/gatsby-plugin-rudderstack/commit/766f8056cf1cc064207bf6caa2108928999d90b9)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## [4.0.0](https://github.com/rudderlabs/gatsby-plugin-rudderstack/compare/v3.0.0...v4.0.0) (2024-03-28)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* use js sdk v3 ([#30](https://github.com/rudderlabs/gatsby-plugin-rudderstack/issues/30)) ([3c81fd7](https://github.com/rudderlabs/gatsby-plugin-rudderstack/commit/3c81fd7eefefdf3afe1f8a28fd5a5eff7b6009c6))
|
|
18
|
+
* 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))
|
|
19
|
+
|
|
5
20
|
## [3.0.0](https://github.com/rudderlabs/gatsby-plugin-rudderstack/compare/v2.0.0...v3.0.0) (2023-12-05)
|
|
6
21
|
|
|
7
22
|
|
package/README.md
CHANGED
|
@@ -120,10 +120,6 @@ plugins: [
|
|
|
120
120
|
// 'defer' will load the SDK as <script defer></script>
|
|
121
121
|
loadType: 'default',
|
|
122
122
|
|
|
123
|
-
// Whether to use the snippet for JS SDK v2.x
|
|
124
|
-
// Useful for only loading the previous major version of the SDK if you do not want to migrate to v3 yet.
|
|
125
|
-
useLegacySDK: false,
|
|
126
|
-
|
|
127
123
|
// Options to the `load` API
|
|
128
124
|
// Note: The above `controlPlaneUrl` overrides the `configUrl` field in this object
|
|
129
125
|
// You can find all the available load options here,
|
package/gatsby-ssr.js
CHANGED
|
@@ -21,8 +21,7 @@ exports.onRenderBody = function (_ref, pluginOptions) {
|
|
|
21
21
|
_pluginOptions$sdkURL = pluginOptions.sdkURL,
|
|
22
22
|
sdkURL = _pluginOptions$sdkURL === void 0 ? 'https://cdn.rudderlabs.com/v3' : _pluginOptions$sdkURL,
|
|
23
23
|
_pluginOptions$loadOp = pluginOptions.loadOptions,
|
|
24
|
-
loadOptions = _pluginOptions$loadOp === void 0 ? {} : _pluginOptions$loadOp
|
|
25
|
-
useLegacySDK = pluginOptions.useLegacySDK;
|
|
24
|
+
loadOptions = _pluginOptions$loadOp === void 0 ? {} : _pluginOptions$loadOp;
|
|
26
25
|
if (!prodKey || prodKey.length < 10) console.error('Your RudderStack prodKey must be at least 10 char in length.');
|
|
27
26
|
if (devKey && devKey.length < 10) console.error('If present, your RudderStack devKey must be at least 10 char in length.');
|
|
28
27
|
var writeKey = process.env.NODE_ENV === 'production' ? prodKey : devKey;
|
|
@@ -30,17 +29,7 @@ exports.onRenderBody = function (_ref, pluginOptions) {
|
|
|
30
29
|
configUrl: controlPlaneUrl || loadOptions.configUrl
|
|
31
30
|
});
|
|
32
31
|
var loadConfig = "'".concat(writeKey, "', '").concat(dataPlaneUrl, "', ").concat(JSON.stringify(finalLoadOptions));
|
|
33
|
-
var snippet = "window.RudderSnippetVersion=\"3.0.
|
|
34
|
-
if (useLegacySDK) {
|
|
35
|
-
var scriptTagStr = "var s = document.createElement(\"script\");\n s.type = \"text/javascript\";\n s.src = \"".concat(sdkURL, "\";");
|
|
36
|
-
if (loadType === 'async') {
|
|
37
|
-
scriptTagStr += 's.async = true;';
|
|
38
|
-
} else if (loadType === 'defer') {
|
|
39
|
-
scriptTagStr += 's.defer = true;';
|
|
40
|
-
}
|
|
41
|
-
scriptTagStr += 'document.head.appendChild(s);';
|
|
42
|
-
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);
|
|
43
|
-
}
|
|
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),asyncScript&&(e.async=true),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()}}();");
|
|
44
33
|
var instantLoader = "".concat(snippet).concat(manualLoad ? "" : "window.rudderanalytics.load(".concat(loadConfig, ")"), ";");
|
|
45
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 ");
|
|
46
35
|
var snippetToUse = "".concat(delayLoad && !manualLoad ? delayedLoader : instantLoader);
|