gatsby-plugin-rudderstack 1.0.5 → 1.1.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.
Files changed (3) hide show
  1. package/README.md +9 -3
  2. package/gatsby-ssr.js +58 -28
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -85,7 +85,7 @@ plugins: [
85
85
  // number (default to 1000); time to wait after the page loads
86
86
  // to load the RudderStack SDK
87
87
  // To be used when `delayLoad` is set to `true`
88
- delayLoadTime: 1000
88
+ delayLoadTime: 1000,
89
89
 
90
90
  // Whether to completely skip calling `analytics.load()`.
91
91
  // ADVANCED FEATURE: only use if you are calling `analytics.load()` manually
@@ -93,13 +93,19 @@ plugins: [
93
93
  // that will call it for you.
94
94
  // Useful for only loading the tracking script once a user has opted in to being tracked, for example.
95
95
  // *Another use case is if you want to add callbacks to the methods at load time.
96
- manualLoad: false
96
+ manualLoad: false,
97
97
 
98
98
  // string ('async' or 'defer'); whether to load the RudderStack SDK async or defer. Anything else
99
99
  // will load normally.
100
100
  // 'async' will load the SDK as <script async></script>
101
101
  // 'defer' will load the SDK as <script defer></script>
102
- loadType: 'default'
102
+ loadType: 'default',
103
+
104
+ // Options to the `load` API
105
+ // Note: The above `controlPlaneUrl` overrides the `configUrl` field in this object
106
+ loadOptions: {
107
+ ...
108
+ }
103
109
  }
104
110
  }
105
111
  ];
package/gatsby-ssr.js CHANGED
@@ -4,38 +4,59 @@ var _react = require("react");
4
4
 
5
5
  var _react2 = _interopRequireDefault(_react);
6
6
 
7
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
+ function _interopRequireDefault(obj) {
8
+ return obj && obj.__esModule ? obj : { default: obj };
9
+ }
8
10
 
9
11
  exports.onRenderBody = function (_ref, pluginOptions) {
10
12
  var setHeadComponents = _ref.setHeadComponents;
11
13
  var trackPage = pluginOptions.trackPage,
12
- prodKey = pluginOptions.prodKey,
13
- devKey = pluginOptions.devKey,
14
- _pluginOptions$dataPl = pluginOptions.dataPlaneUrl,
15
- dataPlaneUrl = _pluginOptions$dataPl === undefined ? "https://hosted.rudderlabs.com" : _pluginOptions$dataPl,
16
- controlPlaneUrl = pluginOptions.controlPlaneUrl,
17
- delayLoad = pluginOptions.delayLoad,
18
- delayLoadTime = pluginOptions.delayLoadTime,
19
- manualLoad = pluginOptions.manualLoad,
20
- loadType = pluginOptions.loadType,
21
- useNewSDK = pluginOptions.useNewSDK;
22
-
14
+ prodKey = pluginOptions.prodKey,
15
+ devKey = pluginOptions.devKey,
16
+ _pluginOptions$dataPl = pluginOptions.dataPlaneUrl,
17
+ dataPlaneUrl =
18
+ _pluginOptions$dataPl === undefined
19
+ ? "https://hosted.rudderlabs.com"
20
+ : _pluginOptions$dataPl,
21
+ controlPlaneUrl = pluginOptions.controlPlaneUrl,
22
+ delayLoad = pluginOptions.delayLoad,
23
+ delayLoadTime = pluginOptions.delayLoadTime,
24
+ manualLoad = pluginOptions.manualLoad,
25
+ loadType = pluginOptions.loadType,
26
+ useNewSDK = pluginOptions.useNewSDK,
27
+ loadOptions = pluginOptions.loadOptions;
23
28
 
24
29
  var sdkSrc = "https://cdn.rudderlabs.com/v1/rudder-analytics.min.js";
25
30
  if (useNewSDK) {
26
31
  sdkSrc = "https://cdn.rudderlabs.com/v1.1/rudder-analytics.min.js";
27
32
  }
28
33
 
29
- if (!prodKey || prodKey.length < 10) console.error("Your Rudderstack prodKey must be at least 10 char in length.");
34
+ if (!prodKey || prodKey.length < 10)
35
+ console.error(
36
+ "Your RudderStack prodKey must be at least 10 char in length."
37
+ );
30
38
 
31
- if (devKey && devKey.length < 10) console.error("If present, your Rudderstack devKey must be at least 10 char in length.");
39
+ if (devKey && devKey.length < 10)
40
+ console.error(
41
+ "If present, your RudderStack devKey must be at least 10 char in length."
42
+ );
32
43
 
33
44
  var writeKey = process.env.NODE_ENV === "production" ? prodKey : devKey;
34
45
 
35
- var loadConfig = controlPlaneUrl ? "'" + writeKey + "', '" + dataPlaneUrl + "', {configUrl: '" + controlPlaneUrl + "'}" : "'" + writeKey + "', '" + dataPlaneUrl + "'";
46
+ var loadConfig = "'" + writeKey + "', '" + dataPlaneUrl + "'";
36
47
 
48
+ if (loadOptions) {
49
+ // Override config URL if provided separately
50
+ loadOptions.configUrl = controlPlaneUrl || loadOptions.configUrl;
51
+ loadConfig += ", " + JSON.stringify(loadOptions);
52
+ }
37
53
 
38
- var 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 " + (delayLoad || manualLoad ? "" : "rudderanalytics.load(" + loadConfig + ")") + ";\n";
54
+ var snippet =
55
+ '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 ' +
56
+ (delayLoad || manualLoad
57
+ ? ""
58
+ : "rudderanalytics.load(" + loadConfig + ")") +
59
+ ";\n";
39
60
 
40
61
  const delayedLoader = `
41
62
  window.rudderSnippetLoaded = false;
@@ -71,30 +92,39 @@ exports.onRenderBody = function (_ref, pluginOptions) {
71
92
  );
72
93
  `;
73
94
 
74
- var snippetToUse = "\n " + (delayLoad && !manualLoad ? delayedLoader : "") + "\n " + snippet + "\n ";
95
+ var snippetToUse =
96
+ "\n " +
97
+ (delayLoad && !manualLoad ? delayedLoader : "") +
98
+ "\n " +
99
+ snippet +
100
+ "\n ";
75
101
 
76
102
  if (writeKey) {
77
- var tags = [_react2.default.createElement("script", {
78
- key: "plugin-rudderstack",
79
- dangerouslySetInnerHTML: { __html: snippetToUse }
80
- })];
103
+ var tags = [
104
+ _react2.default.createElement("script", {
105
+ key: "plugin-rudderstack",
106
+ dangerouslySetInnerHTML: { __html: snippetToUse },
107
+ }),
108
+ ];
81
109
 
82
110
  var tag = void 0;
83
111
 
84
- if (loadType == 'async') {
85
- tag = _react2.default.createElement("script", { async: true,
112
+ if (loadType == "async") {
113
+ tag = _react2.default.createElement("script", {
114
+ async: true,
86
115
  key: "rudderstack-cdn",
87
- src: sdkSrc
116
+ src: sdkSrc,
88
117
  });
89
- } else if (loadType == 'defer') {
90
- tag = _react2.default.createElement("script", { defer: true,
118
+ } else if (loadType == "defer") {
119
+ tag = _react2.default.createElement("script", {
120
+ defer: true,
91
121
  key: "rudderstack-cdn",
92
- src: sdkSrc
122
+ src: sdkSrc,
93
123
  });
94
124
  } else {
95
125
  tag = _react2.default.createElement("script", {
96
126
  key: "rudderstack-cdn",
97
- src: sdkSrc
127
+ src: sdkSrc,
98
128
  });
99
129
  }
100
130
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gatsby-plugin-rudderstack",
3
- "version": "1.0.5",
4
- "description": "Event tracking with Rudderstack in your Gatsby frontend.",
3
+ "version": "1.1.0",
4
+ "description": "Event tracking with RudderStack in your Gatsby frontend.",
5
5
  "main": "gatsby-ssr.js",
6
6
  "scripts": {
7
7
  "build": "babel src --out-dir . --ignore __tests__",
@@ -18,7 +18,7 @@
18
18
  "gatsby",
19
19
  "gatsby-plugin"
20
20
  ],
21
- "author": "Rudderstack",
21
+ "author": "RudderStack",
22
22
  "license": "AGPL-3.0-only",
23
23
  "bugs": {
24
24
  "url": "https://github.com/rudderlabs/gatsby-plugin-rudderstack/issues"