gatsby-plugin-rudderstack 1.1.2 → 3.0.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/package.json CHANGED
@@ -1,11 +1,26 @@
1
1
  {
2
2
  "name": "gatsby-plugin-rudderstack",
3
- "version": "1.1.2",
3
+ "version": "3.0.0-beta.0",
4
4
  "description": "Event tracking with RudderStack in your Gatsby frontend.",
5
5
  "main": "gatsby-ssr.js",
6
6
  "scripts": {
7
- "build": "babel src --out-dir . --ignore __tests__",
8
- "watch": "babel -w src --out-dir . --ignore __tests__"
7
+ "build": "babel src --out-dir ./dist --ignore __tests__ && npm run copy:files",
8
+ "watch": "babel -w src --out-dir ./dist --ignore __tests__",
9
+ "clean": "rm -rf dist",
10
+ "check:lint": "eslint \"src/**/*.js\"",
11
+ "check:lint:ci": "eslint \"src/**/*.js\" -f json -o reports/eslint.json || exit 0",
12
+ "check:circular": "madge --circular --extensions js ./src || exit 0",
13
+ "check:duplicates": "jscpd src --threshold 5",
14
+ "check:security": "npm audit --recursive --audit-level=high",
15
+ "format": "prettier --write .",
16
+ "lint:fix": "eslint . --fix",
17
+ "prepare": "husky install",
18
+ "pre-commit": "npm run test && npx lint-staged",
19
+ "commit-msg": "commitlint --edit",
20
+ "commit": "git-cz",
21
+ "test": "exit 0",
22
+ "test:ci": "exit 0",
23
+ "copy:files": "cp CHANGELOG.md dist/ && cp LICENSE.md dist/ && cp package.json dist/ && cp gatsby-node.js dist/ && cp README.md dist/"
9
24
  },
10
25
  "repository": {
11
26
  "type": "git",
@@ -19,19 +34,65 @@
19
34
  "gatsby-plugin"
20
35
  ],
21
36
  "author": "RudderStack",
22
- "license": "AGPL-3.0-only",
37
+ "license": "MIT",
23
38
  "bugs": {
24
39
  "url": "https://github.com/rudderlabs/gatsby-plugin-rudderstack/issues"
25
40
  },
26
41
  "homepage": "https://github.com/rudderlabs/gatsby-plugin-rudderstack#readme",
27
42
  "devDependencies": {
28
- "babel-cli": "^6.24.1",
29
- "babel-preset-env": "^1.6.1",
30
- "babel-preset-react": "^6.24.1"
43
+ "@babel/cli": "^7.19.3",
44
+ "@babel/core": "^7.20.2",
45
+ "@babel/eslint-parser": "7.19.1",
46
+ "@babel/plugin-proposal-object-rest-spread": "^7.20.2",
47
+ "@babel/preset-env": "^7.20.2",
48
+ "@babel/preset-react": "^7.18.6",
49
+ "commitizen": "4.2.5",
50
+ "commitlint": "17.3.0",
51
+ "conventional-changelog-cli": "2.2.2",
52
+ "conventional-github-releaser": "3.1.5",
53
+ "@commitlint/config-conventional": "17.3.0",
54
+ "@digitalroute/cz-conventional-changelog-for-jira": "7.4.2",
55
+ "eslint": "8.28.0",
56
+ "eslint-config-airbnb": "19.0.4",
57
+ "eslint-config-airbnb-base": "15.0.0",
58
+ "eslint-config-prettier": "8.5.0",
59
+ "eslint-plugin-compat": "4.0.2",
60
+ "eslint-plugin-import": "2.26.0",
61
+ "eslint-plugin-sonarjs": "0.16.0",
62
+ "eslint-plugin-unicorn": "45.0.0",
63
+ "husky": "8.0.2",
64
+ "jscpd": "3.5.1",
65
+ "lint-staged": "13.0.4",
66
+ "madge": "5.0.1",
67
+ "prettier": "2.8.0",
68
+ "standard-version": "9.5.0"
31
69
  },
32
70
  "eslintConfig": {
33
71
  "rules": {
34
72
  "strict": "off"
35
73
  }
74
+ },
75
+ "lint-staged": {
76
+ "*.js": "eslint --cache --fix",
77
+ "*.{json,js,md,ts}": "prettier --write"
78
+ },
79
+ "config": {
80
+ "commitizen": {
81
+ "path": "./node_modules/@digitalroute/cz-conventional-changelog-for-jira",
82
+ "jiraMode": false,
83
+ "jiraOptional": true,
84
+ "skipScope": true,
85
+ "defaultType": "feat"
86
+ }
87
+ },
88
+ "overrides": {
89
+ "dot-prop": "5.3.0",
90
+ "semver-regex": "3.1.4",
91
+ "trim-newlines": "3.0.1"
92
+ },
93
+ "resolutions": {
94
+ "dot-prop": "5.3.0",
95
+ "semver-regex": "3.1.4",
96
+ "trim-newlines": "3.0.1"
36
97
  }
37
98
  }
@@ -0,0 +1,35 @@
1
+ sonar.log.level=INFO
2
+ sonar.verbose=false
3
+ sonar.qualitygate.wait=false
4
+
5
+ # Project details
6
+ sonar.projectKey=rudderlabs_gatsby-plugin-rudderstack
7
+ sonar.organization=rudderlabs
8
+ sonar.projectName=gatsby-plugin-rudderstack
9
+ sonar.projectVersion=2.0.0
10
+
11
+ # Meta-data for the project
12
+ sonar.links.scm=https://github.com/rudderlabs/gatsby-plugin-rudderstack
13
+ sonar.links.issue=https://github.com/rudderlabs/gatsby-plugin-rudderstack/issues
14
+
15
+ # Path to reports
16
+ # sonar.javascript.lcov.reportPaths=reports/coverage/lcov.info
17
+ # sonar.testExecutionReportPaths=reports/sonar/results-report.xml
18
+ sonar.eslint.reportPaths=reports/eslint.json
19
+
20
+ # Path to sources
21
+ sonar.sources=src
22
+ sonar.inclusions=**/*.js
23
+ sonar.exclusions=**/*.json,**/*.html,**/*.png,**/*.jpg,**/*.gif,**/*.svg
24
+
25
+ # Path to tests
26
+ # sonar.tests=__tests__
27
+ # sonar.test.inclusions=**/*.test.js
28
+ # sonar.test.exclusions=**/*.json,**/*.html,**/*.png,**/*.jpg,**/*.gif,**/*.svg
29
+ # sonar.coverage.exclusions=test/**/*,__tests__/**/*,__mocks__/**/*,examples/**/*,**/*.json,**/*.html,**/*.png,**/*.jpg,**/*.gif,**/*.svg
30
+
31
+ # Source encoding
32
+ sonar.sourceEncoding=UTF-8
33
+
34
+ # Exclusions for copy-paste detection
35
+ sonar.cpd.exclusions=test/**/*,__tests__/**/*,__mocks__/**/*,examples/**/*
package/CHANGELOG.md DELETED
File without changes
package/gatsby-browser.js DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- exports.onRouteUpdate = function (_ref, _ref2) {
4
- var prevLocation = _ref.prevLocation;
5
- var trackPage = _ref2.trackPage,
6
- _ref2$trackPageDelay = _ref2.trackPageDelay,
7
- trackPageDelay = _ref2$trackPageDelay === undefined ? 50 : _ref2$trackPageDelay;
8
-
9
- function trackRudderStackPage() {
10
- if (trackPage) {
11
- // Adding a delay (defaults to 50ms when not provided by plugin option `trackPageDelay`)
12
- // ensure that the RudderStack route tracking is in sync with the actual Gatsby route
13
- // (otherwise you can end up in a state where the RudderStack page tracking reports
14
- // the previous page on route change).
15
- var delay = Math.max(0, trackPageDelay);
16
-
17
- window.setTimeout(function () {
18
- window.rudderanalytics && window.rudderanalytics.page(document.title);
19
- }, delay);
20
- }
21
- }
22
-
23
- // IMPORTANT: If you are cloning the contents of this file,
24
- // we recommend to keep this section of the code intact and
25
- // just change the tracking logic in `trackRudderStackPage` method.
26
- if (window.rudderSnippetLoaded === false) {
27
- if (window.rudderSnippetLoading === true) {
28
- // As the loading is in progress, set the alternate callback function
29
- // to track page
30
- window.rudderSnippetLoadedCallback = function () {
31
- trackRudderStackPage();
32
- };
33
- } else {
34
- // if it is not the first page
35
- if (prevLocation) {
36
- // Trigger the script loader and set the callback function
37
- // to track page
38
- window.rudderSnippetLoadedCallback = undefined;
39
- window.rudderSnippetLoader(function () {
40
- trackRudderStackPage();
41
- });
42
- } else {
43
- // As this is the first page, set the alternate callback function
44
- // to track page and wait for the scroll event to occur (for SDK to get loaded)
45
- window.rudderSnippetLoadedCallback = function () {
46
- trackRudderStackPage();
47
- }
48
- }
49
- }
50
- } else {
51
- trackRudderStackPage();
52
- }
53
- };
package/gatsby-ssr.js DELETED
@@ -1,139 +0,0 @@
1
- "use strict";
2
-
3
- var _react = require("react");
4
-
5
- var _react2 = _interopRequireDefault(_react);
6
-
7
- function _interopRequireDefault(obj) {
8
- return obj && obj.__esModule ? obj : { default: obj };
9
- }
10
-
11
- exports.onRenderBody = function (_ref, pluginOptions) {
12
- var setHeadComponents = _ref.setHeadComponents;
13
- var trackPage = pluginOptions.trackPage,
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
- useBetaSDK = pluginOptions.useBetaSDK,
28
- loadOptions = pluginOptions.loadOptions,
29
- sdkURL = pluginOptions.sdkURL;
30
-
31
- var sdkSrc = "https://cdn.rudderlabs.com/v1/rudder-analytics.min.js";
32
- if (sdkURL) sdkSrc = sdkURL;
33
- else if (useBetaSDK) {
34
- sdkSrc = "https://cdn.rudderlabs.com/v1.1/beta/rudder-analytics.min.js";
35
- } else if (useNewSDK) {
36
- sdkSrc = "https://cdn.rudderlabs.com/v1.1/rudder-analytics.min.js";
37
- }
38
-
39
- if (!prodKey || prodKey.length < 10)
40
- console.error(
41
- "Your RudderStack prodKey must be at least 10 char in length."
42
- );
43
-
44
- if (devKey && devKey.length < 10)
45
- console.error(
46
- "If present, your RudderStack devKey must be at least 10 char in length."
47
- );
48
-
49
- var writeKey = process.env.NODE_ENV === "production" ? prodKey : devKey;
50
-
51
- var loadConfig = "'" + writeKey + "', '" + dataPlaneUrl + "'";
52
-
53
- if (loadOptions) {
54
- // Override config URL if provided separately
55
- loadOptions.configUrl = controlPlaneUrl || loadOptions.configUrl;
56
- loadConfig += ", " + JSON.stringify(loadOptions);
57
- }
58
-
59
- var snippet =
60
- '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 ' +
61
- (delayLoad || manualLoad
62
- ? ""
63
- : "rudderanalytics.load(" + loadConfig + ")") +
64
- ";\n";
65
-
66
- const delayedLoader = `
67
- window.rudderSnippetLoaded = false;
68
- window.rudderSnippetLoading = false;
69
- window.rudderSnippetLoadedCallback = undefined;
70
- window.rudderSnippetLoader = function (callback) {
71
- if (!window.rudderSnippetLoaded && !window.rudderSnippetLoading) {
72
- window.rudderSnippetLoading = true;
73
- function loader() {
74
- window.rudderanalytics.load(${loadConfig});
75
- window.rudderSnippetLoading = false;
76
- window.rudderSnippetLoaded = true;
77
- if (callback) { callback(); }
78
- if (window.rudderSnippetLoadedCallback) {
79
- window.rudderSnippetLoadedCallback();
80
- window.rudderSnippetLoadedCallback = undefined;
81
- }
82
- };
83
-
84
- "requestIdleCallback" in window
85
- ? requestIdleCallback(function () { loader(); })
86
- : loader();
87
- }
88
- }
89
- window.addEventListener('scroll',function () {window.rudderSnippetLoader()}, { once: true });
90
- setTimeout(
91
- function () {
92
- "requestIdleCallback" in window
93
- ? requestIdleCallback(function () { window.rudderSnippetLoader(); })
94
- : window.rudderSnippetLoader();
95
- },
96
- ${delayLoadTime} || 1000
97
- );
98
- `;
99
-
100
- var snippetToUse =
101
- "\n " +
102
- (delayLoad && !manualLoad ? delayedLoader : "") +
103
- "\n " +
104
- snippet +
105
- "\n ";
106
-
107
- if (writeKey) {
108
- var tags = [
109
- _react2.default.createElement("script", {
110
- key: "plugin-rudderstack",
111
- dangerouslySetInnerHTML: { __html: snippetToUse },
112
- }),
113
- ];
114
-
115
- var tag = void 0;
116
-
117
- if (loadType == "async") {
118
- tag = _react2.default.createElement("script", {
119
- async: true,
120
- key: "rudderstack-cdn",
121
- src: sdkSrc,
122
- });
123
- } else if (loadType == "defer") {
124
- tag = _react2.default.createElement("script", {
125
- defer: true,
126
- key: "rudderstack-cdn",
127
- src: sdkSrc,
128
- });
129
- } else {
130
- tag = _react2.default.createElement("script", {
131
- key: "rudderstack-cdn",
132
- src: sdkSrc,
133
- });
134
- }
135
-
136
- tags.push(tag);
137
- setHeadComponents(tags);
138
- }
139
- };
package/index.js DELETED
@@ -1 +0,0 @@
1
- // noop