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/.eslintcache +1 -0
- package/.eslintignore +8 -0
- package/.eslintrc.json +41 -0
- package/.github/workflows/build-and-quality-checks.yml +36 -0
- package/.github/workflows/check_pr_title.yml +17 -0
- package/.github/workflows/codeql-analysis.yml +70 -0
- package/.github/workflows/create-hotfix-branch.yml +21 -0
- package/.github/workflows/deploy-npm.yml +82 -0
- package/.github/workflows/draft-new-release.yml +86 -0
- package/.github/workflows/housekeeping.yaml +40 -0
- package/.github/workflows/notion-pr-sync.yml +55 -0
- package/.github/workflows/publish-new-release.yml +111 -0
- package/.github/workflows/test.yml +44 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +4 -0
- package/.idea/gatsby-plugin-rudderstack.iml +10 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.nvmrc +1 -0
- package/.prettierignore +6 -0
- package/.prettierrc +7 -0
- package/CODEOWNERS +2 -2
- package/README.md +14 -7
- package/commitlint.config.js +3 -0
- package/dist/LICENSE.md +21 -0
- package/dist/README.md +331 -0
- package/dist/gatsby-browser.js +36 -0
- package/dist/gatsby-node.js +1 -0
- package/dist/gatsby-ssr.js +60 -0
- package/dist/package.json +98 -0
- package/package.json +68 -7
- package/sonar-project.properties +35 -0
- package/CHANGELOG.md +0 -0
- package/gatsby-browser.js +0 -53
- package/gatsby-ssr.js +0 -139
- package/index.js +0 -1
package/.prettierrc
ADDED
package/CODEOWNERS
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
* @
|
|
2
|
-
* @
|
|
1
|
+
* @bardisg
|
|
2
|
+
* @MoumitaM
|
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ plugins: [
|
|
|
40
40
|
// required; non-empty string
|
|
41
41
|
//NOTE: Do not commit this to git. Process from env.
|
|
42
42
|
prodKey: `RUDDERSTACK_PRODUCTION_WRITE_KEY`,
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
// if you have a development env for your rudderstack account, paste that key here
|
|
45
45
|
// when process.env.NODE_ENV === 'development'
|
|
46
46
|
// optional; non-empty string
|
|
@@ -59,18 +59,19 @@ plugins: [
|
|
|
59
59
|
// If you need to proxy events through a custom data plane,
|
|
60
60
|
// add a `dataPlaneUrl` property (defaults to https://hosted.rudderlabs.com )
|
|
61
61
|
// RudderStack docs:
|
|
62
|
-
// - https://
|
|
62
|
+
// - https://rudderstack.com/docs/sources/event-streams/sdks/rudderstack-javascript-sdk/#31-load
|
|
63
63
|
dataPlaneUrl: `https://override-rudderstack-endpoint`,
|
|
64
64
|
|
|
65
65
|
// Add a `controlPlaneUrl` property if you are self-hosting the Control Plane
|
|
66
66
|
// RudderStack docs:
|
|
67
|
-
// - https://
|
|
67
|
+
// - https://rudderstack.com/docs/sources/event-streams/sdks/rudderstack-javascript-sdk/#311-self-hosted-control-plane
|
|
68
68
|
controlPlaneUrl: `https://override-control-plane-url`,
|
|
69
69
|
|
|
70
|
-
// boolean (defaults to false); whether to delay load RudderStack
|
|
70
|
+
// boolean (defaults to false); whether to delay loading (add SDK script and load the SDK) of RudderStack JS SDK.
|
|
71
71
|
// ADVANCED FEATURE: only use if you leverage client-side routing (ie, Gatsby <Link>)
|
|
72
72
|
// This feature will force RudderStack to load _after_ either a page routing change
|
|
73
|
-
// or user scroll,
|
|
73
|
+
// or user scroll, whichever comes first. This delay time is controlled by
|
|
74
|
+
// `delayLoadTime` setting. This feature is used to help improve your website's
|
|
74
75
|
// TTI (for SEO, UX, etc). See links below for more info.
|
|
75
76
|
// NOTE: But if you are using server-side routing and enable this feature,
|
|
76
77
|
// RudderStack will never load (because although client-side routing does not do
|
|
@@ -82,8 +83,7 @@ plugins: [
|
|
|
82
83
|
// Problem/solution: https://marketingexamples.com/seo/performance
|
|
83
84
|
delayLoad: false,
|
|
84
85
|
|
|
85
|
-
// number (default to 1000); time to wait after
|
|
86
|
-
// to load the RudderStack SDK
|
|
86
|
+
// number (default to 1000); time to wait after scroll or route change
|
|
87
87
|
// To be used when `delayLoad` is set to `true`
|
|
88
88
|
delayLoadTime: 1000,
|
|
89
89
|
|
|
@@ -95,6 +95,11 @@ plugins: [
|
|
|
95
95
|
// *Another use case is if you want to add callbacks to the methods at load time.
|
|
96
96
|
manualLoad: false,
|
|
97
97
|
|
|
98
|
+
// Can be used to override where the SDK should be loaded from. This is useful
|
|
99
|
+
// if you want to serve the SDK from a custom domain other than RudderStack to tackle ad-blockers
|
|
100
|
+
// By default, the plugin will use the latest JS SDK from RudderStack's CDN
|
|
101
|
+
sdkURL: `https://subdomain.yourdomain.com/v1.1/rudder-analytics.min.js`,
|
|
102
|
+
|
|
98
103
|
// string ('async' or 'defer'); whether to load the RudderStack SDK async or defer. Anything else
|
|
99
104
|
// will load normally.
|
|
100
105
|
// 'async' will load the SDK as <script async></script>
|
|
@@ -103,6 +108,8 @@ plugins: [
|
|
|
103
108
|
|
|
104
109
|
// Options to the `load` API
|
|
105
110
|
// Note: The above `controlPlaneUrl` overrides the `configUrl` field in this object
|
|
111
|
+
// You can find all the available load options here,
|
|
112
|
+
// https://www.rudderstack.com/docs/sources/event-streams/sdks/rudderstack-javascript-sdk/load-js-sdk/#loading-options
|
|
106
113
|
loadOptions: {
|
|
107
114
|
...
|
|
108
115
|
}
|
package/dist/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 RudderStack
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/README.md
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
<p align="center"><a href="https://rudderstack.com"><img src="https://user-images.githubusercontent.com/59817155/121357083-1c571300-c94f-11eb-8cc7-ce6df13855c9.png" alt="RudderStack - An Open Source Customer Data Platform" height="90"/></a></p>
|
|
2
|
+
<h1 align="center">gatsby-plugin-rudderstack</h1>
|
|
3
|
+
<p align="center"><b>The warehouse-first customer data platform built for devs.</b></p>
|
|
4
|
+
<br/>
|
|
5
|
+
|
|
6
|
+
# The RudderStack Plugin for Gatsby.
|
|
7
|
+
|
|
8
|
+
This is a way for you to quickly and easily get RudderStack up and running in your Gatsby application.
|
|
9
|
+
|
|
10
|
+
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
|
+
|
|
12
|
+
# Why Use This plugin
|
|
13
|
+
|
|
14
|
+
This plugin makes it easy to integrate your Gatsby website with the RudderStack API and easily track events.
|
|
15
|
+
|
|
16
|
+
# Key Features
|
|
17
|
+
|
|
18
|
+
- use multiple write keys (one for prod env, another optional one for dev)
|
|
19
|
+
- disable page view tracking (just in case you want to add it later manually)
|
|
20
|
+
- up to date (RudderStack team maintained)
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
- NPM: `$ npm install --save gatsby-plugin-rudderstack`
|
|
25
|
+
- YARN: `$ yarn add gatsby-plugin-rudderstack`
|
|
26
|
+
|
|
27
|
+
# [](https://github.com/rudderlabs/gatsby-plugin-rudderstack/blob/master/README.md#setup) Setup
|
|
28
|
+
|
|
29
|
+
## [](https://github.com/rudderlabs/gatsby-plugin-rudderstack/blob/master/README.md#step-1-configure-gatsby) Step 1: Configure Your Gatsby Config File
|
|
30
|
+
|
|
31
|
+
In your gatsby-config.js file:
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
plugins: [
|
|
35
|
+
{
|
|
36
|
+
resolve: `gatsby-plugin-rudderstack`,
|
|
37
|
+
options: {
|
|
38
|
+
// your rudderstack write key for your production environment
|
|
39
|
+
// when process.env.NODE_ENV === 'production'
|
|
40
|
+
// required; non-empty string
|
|
41
|
+
//NOTE: Do not commit this to git. Process from env.
|
|
42
|
+
prodKey: `RUDDERSTACK_PRODUCTION_WRITE_KEY`,
|
|
43
|
+
|
|
44
|
+
// if you have a development env for your rudderstack account, paste that key here
|
|
45
|
+
// when process.env.NODE_ENV === 'development'
|
|
46
|
+
// optional; non-empty string
|
|
47
|
+
//NOTE: Do not commit this to git. Process from env.
|
|
48
|
+
devKey: `RUDDERSTACK_DEV_WRITE_KEY`,
|
|
49
|
+
|
|
50
|
+
// boolean (defaults to false) on whether you want
|
|
51
|
+
// to include analytics.page() automatically
|
|
52
|
+
// if false, see below on how to track pageviews manually
|
|
53
|
+
trackPage: false,
|
|
54
|
+
|
|
55
|
+
// number (defaults to 50); time to wait after a route update before it should
|
|
56
|
+
// track the page change, to implement this, make sure your `trackPage` property is set to `true`
|
|
57
|
+
trackPageDelay: 50,
|
|
58
|
+
|
|
59
|
+
// If you need to proxy events through a custom data plane,
|
|
60
|
+
// add a `dataPlaneUrl` property (defaults to https://hosted.rudderlabs.com )
|
|
61
|
+
// RudderStack docs:
|
|
62
|
+
// - https://rudderstack.com/docs/sources/event-streams/sdks/rudderstack-javascript-sdk/#31-load
|
|
63
|
+
dataPlaneUrl: `https://override-rudderstack-endpoint`,
|
|
64
|
+
|
|
65
|
+
// Add a `controlPlaneUrl` property if you are self-hosting the Control Plane
|
|
66
|
+
// RudderStack docs:
|
|
67
|
+
// - https://rudderstack.com/docs/sources/event-streams/sdks/rudderstack-javascript-sdk/#311-self-hosted-control-plane
|
|
68
|
+
controlPlaneUrl: `https://override-control-plane-url`,
|
|
69
|
+
|
|
70
|
+
// boolean (defaults to false); whether to delay loading (add SDK script and load the SDK) of RudderStack JS SDK.
|
|
71
|
+
// ADVANCED FEATURE: only use if you leverage client-side routing (ie, Gatsby <Link>)
|
|
72
|
+
// This feature will force RudderStack to load _after_ either a page routing change
|
|
73
|
+
// or user scroll, whichever comes first. This delay time is controlled by
|
|
74
|
+
// `delayLoadTime` setting. This feature is used to help improve your website's
|
|
75
|
+
// TTI (for SEO, UX, etc). See links below for more info.
|
|
76
|
+
// NOTE: But if you are using server-side routing and enable this feature,
|
|
77
|
+
// RudderStack will never load (because although client-side routing does not do
|
|
78
|
+
// a full page refresh, server-side routing does, thereby preventing RudderStack
|
|
79
|
+
// from ever loading).
|
|
80
|
+
// See here for more context:
|
|
81
|
+
// GIF: https://github.com/benjaminhoffman/gatsby-plugin-segment/pull/19#issuecomment-559569483
|
|
82
|
+
// TTI: https://github.com/GoogleChrome/lighthouse/blob/master/docs/scoring.md#performance
|
|
83
|
+
// Problem/solution: https://marketingexamples.com/seo/performance
|
|
84
|
+
delayLoad: false,
|
|
85
|
+
|
|
86
|
+
// number (default to 1000); time to wait after scroll or route change
|
|
87
|
+
// To be used when `delayLoad` is set to `true`
|
|
88
|
+
delayLoadTime: 1000,
|
|
89
|
+
|
|
90
|
+
// Whether to completely skip calling `analytics.load()`.
|
|
91
|
+
// ADVANCED FEATURE: only use if you are calling `analytics.load()` manually
|
|
92
|
+
// elsewhere in your code or are using a library
|
|
93
|
+
// that will call it for you.
|
|
94
|
+
// Useful for only loading the tracking script once a user has opted in to being tracked, for example.
|
|
95
|
+
// *Another use case is if you want to add callbacks to the methods at load time.
|
|
96
|
+
manualLoad: false,
|
|
97
|
+
|
|
98
|
+
// Can be used to override where the SDK should be loaded from. This is useful
|
|
99
|
+
// if you want to serve the SDK from a custom domain other than RudderStack to tackle ad-blockers
|
|
100
|
+
// By default, the plugin will use the latest JS SDK from RudderStack's CDN
|
|
101
|
+
sdkURL: `https://subdomain.yourdomain.com/v1.1/rudder-analytics.min.js`,
|
|
102
|
+
|
|
103
|
+
// string ('async' or 'defer'); whether to load the RudderStack SDK async or defer. Anything else
|
|
104
|
+
// will load normally.
|
|
105
|
+
// 'async' will load the SDK as <script async></script>
|
|
106
|
+
// 'defer' will load the SDK as <script defer></script>
|
|
107
|
+
loadType: 'default',
|
|
108
|
+
|
|
109
|
+
// Options to the `load` API
|
|
110
|
+
// Note: The above `controlPlaneUrl` overrides the `configUrl` field in this object
|
|
111
|
+
// You can find all the available load options here,
|
|
112
|
+
// https://www.rudderstack.com/docs/sources/event-streams/sdks/rudderstack-javascript-sdk/load-js-sdk/#loading-options
|
|
113
|
+
loadOptions: {
|
|
114
|
+
...
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
];
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## [](https://github.com/rudderlabs/gatsby-plugin-rudderstack/blob/master/README.md#step-2-identify-your-users-using-the-identify-method)Step 2: Identify Your Users With the `identify()` Method:
|
|
122
|
+
|
|
123
|
+
The `identify()` method allows you to link users and their actions to a specific userid.
|
|
124
|
+
|
|
125
|
+
A sample example of how the `identify()` method works in Gatsby is as shown:
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
class CallToAction extends React.Component {
|
|
129
|
+
_handleCallToAction() {
|
|
130
|
+
window.rudderanalytics.identify(
|
|
131
|
+
"12345", {
|
|
132
|
+
email: "name@domain.com"
|
|
133
|
+
}, {
|
|
134
|
+
page: {
|
|
135
|
+
path: "/post",
|
|
136
|
+
referrer: "internal",
|
|
137
|
+
search: "",
|
|
138
|
+
title: "Post Page",
|
|
139
|
+
url: "",
|
|
140
|
+
},
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
render() {
|
|
145
|
+
return (
|
|
146
|
+
<Link onClick={ this._handleCallToAction } to="/write-post">Write a Post</Link>
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
In the above example, information such as the user ID, email along with contextual information such as IP address, anonymousId, etc. will be captured.
|
|
153
|
+
|
|
154
|
+
> **NOTE**: There is no need to call `identify()` for anonymous visitors to your website. Such visitors are automatically assigned an `anonymousId`.
|
|
155
|
+
|
|
156
|
+
## [](https://github.com/rudderlabs/rudder-sdk-js/blob/master/README.md#step-3-track-your-users-actions-using-the-track-method)Step 3: Track Your Users’ Actions With the `track()` Method
|
|
157
|
+
|
|
158
|
+
The `track()` method allows you to track any actions that your users might perform.
|
|
159
|
+
|
|
160
|
+
A sample example of how the `track()` method works is as shown:
|
|
161
|
+
|
|
162
|
+
```javascript
|
|
163
|
+
window.rudderanalytics.track(
|
|
164
|
+
"test track event GA3",
|
|
165
|
+
{
|
|
166
|
+
revenue: 30,
|
|
167
|
+
currency: "USD",
|
|
168
|
+
user_actual_id: 12345,
|
|
169
|
+
},
|
|
170
|
+
() => {
|
|
171
|
+
console.log("in track call");
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
In the above example, the method tracks the event ‘**test track event GA3**’, and information such as the revenue, currency, anonymousId.
|
|
177
|
+
|
|
178
|
+
You can use this method to track various other success metrics for your website, such as user signups, item purchases, article bookmarks, and much more.
|
|
179
|
+
|
|
180
|
+
> **NOTE**: To override contextual information, for ex: anonymizing IP and other contextual fields like page properties, the following template can be used. Similarly one can override the auto-generated anonymousId with provided ID. For this:
|
|
181
|
+
|
|
182
|
+
```javascript
|
|
183
|
+
window.rudderanalytics.track(
|
|
184
|
+
"test track event GA3",
|
|
185
|
+
{
|
|
186
|
+
revenue: 30,
|
|
187
|
+
currency: "USD",
|
|
188
|
+
user_actual_id: 12345,
|
|
189
|
+
},
|
|
190
|
+
() => {
|
|
191
|
+
console.log("in track call");
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Track Pageviews
|
|
197
|
+
|
|
198
|
+
**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
|
+
|
|
200
|
+
```javascript
|
|
201
|
+
// gatsby-browser.js
|
|
202
|
+
exports.onRouteUpdate = () => {
|
|
203
|
+
window.rudderanalytics && window.rudderanalytics.page();
|
|
204
|
+
};
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Note: The above code snippet might not give the best results all the time as it doesn't take various SDK loading scenarios into consideration. Hence, if you are not tracking page views automatically, then clone the contents of the `gatsby-browser.js` from the package and make necessary modifications.
|
|
208
|
+
|
|
209
|
+
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
|
+
|
|
211
|
+
## [](https://github.com/rudderlabs/rudder-sdk-js/blob/master/README.md#step-4-check-ready-state)Step 4: Check Ready State
|
|
212
|
+
|
|
213
|
+
**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
|
+
|
|
215
|
+
For example:
|
|
216
|
+
|
|
217
|
+
```javascript
|
|
218
|
+
window.rudderanalytics.ready(() => {
|
|
219
|
+
console.log("we are all set!!!");
|
|
220
|
+
});
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
| **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
|
+
| :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
225
|
+
|
|
226
|
+
# [](https://github.com/rudderlabs/rudder-sdk-js/blob/master/README.md#querystring-api)Querystring API
|
|
227
|
+
|
|
228
|
+
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
|
+
|
|
230
|
+
For example:
|
|
231
|
+
|
|
232
|
+
```html
|
|
233
|
+
http://hostname.com/?ajs_uid=12345&ajs_event=test%20event&ajs_aid=abcde&ajs_prop_testProp=prop1&ajs_trait_name=Firstname+Lastname
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
For the above URL, the below SDK calls will be triggered:
|
|
237
|
+
|
|
238
|
+
```javascript
|
|
239
|
+
rudderanalytics.identify("12345", { name: "Firstname Lastname" });
|
|
240
|
+
rudderanalytics.track("test event", { testProp: "prop1" });
|
|
241
|
+
rudderanalytics.setAnonymousId("abcde");
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
You may use the below parameters as querystring parameter and trigger the corresponding call.
|
|
245
|
+
|
|
246
|
+
`ajs_uid` : Makes a `rudderanalytics.identify()` call with `userId` having the value of the parameter value.
|
|
247
|
+
|
|
248
|
+
`ajs_aid` : Makes a `rudderanalytics.setAnonymousId()` call with `anonymousId` having the value of the parameter value.
|
|
249
|
+
|
|
250
|
+
`ajs_event` : Makes a `rudderanalytics.track()` call with `event` name as parameter value.
|
|
251
|
+
|
|
252
|
+
`ajs_prop_<property>` : If `ajs_event` is passed as querystring, value of this parameter will populate the `properties` of the corresponding event in the `track` call.
|
|
253
|
+
|
|
254
|
+
`ajs_trait_<trait>` : If `ajs_uid` is provided as querysting, value of this parameter will populate the `traits` of the `identify` call made.
|
|
255
|
+
|
|
256
|
+
# [](https://github.com/rudderlabs/rudder-sdk-js/blob/master/README.md#adding-callbacks-to-standard-methods)Adding Callbacks to Standard Methods
|
|
257
|
+
|
|
258
|
+
You can also define callbacks to the common methods of the `rudderanalytics` object.
|
|
259
|
+
|
|
260
|
+
> **Note**: For now, the functionality is supported for `syncPixel` method which is called in the SDK when making sync calls in integrations for relevant destinations.
|
|
261
|
+
|
|
262
|
+
For example, you can load the rudderanalytics with callbacks in your Gatsby browser file:
|
|
263
|
+
|
|
264
|
+
```javascript
|
|
265
|
+
window.rudderanalytics.syncPixelCallback = (obj) => {
|
|
266
|
+
window.rudderanalytics.track(
|
|
267
|
+
"sync lotame",
|
|
268
|
+
{ destination: obj.destination },
|
|
269
|
+
{ integrations: { All: false, S3: true } }
|
|
270
|
+
);
|
|
271
|
+
};
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Note: in order for this to work well, you must also set the manualLoad option to true in your Gatsby configuration, and load rudderstack in the browser gatsby file manually.
|
|
275
|
+
|
|
276
|
+
In the above example, we are defining a `syncPixelCallback` on the analytics object before the call to load the SDK. This will lead to calling of this registered callback with the parameter `{destination: <destination_name>}` whenever a sync call is made from the SDK for relevant integrations like _Lotame_.
|
|
277
|
+
|
|
278
|
+
The callback can be supplied in options parameter like below as well:
|
|
279
|
+
|
|
280
|
+
```javascript
|
|
281
|
+
// Define the callbacks directly on the load method like:
|
|
282
|
+
rudderanalytics.load(YOUR_WRITE_KEY, DATA_PLANE_URL, {
|
|
283
|
+
clientSuppliedCallbacks: {
|
|
284
|
+
syncPixelCallback: () => {
|
|
285
|
+
console.log("sync done!");
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
# License
|
|
292
|
+
|
|
293
|
+
RudderStack **gatsby-plugin-rudderstack** is released under the [AGPLv3 License][agplv3_license].
|
|
294
|
+
|
|
295
|
+
# Contribute
|
|
296
|
+
|
|
297
|
+
We would love to see you contribute to RudderStack. Get more information on how to contribute [here](CONTRIBUTING.md).
|
|
298
|
+
|
|
299
|
+
# Follow Us
|
|
300
|
+
|
|
301
|
+
- [RudderStack Blog][rudderstack-blog]
|
|
302
|
+
- [Slack][slack]
|
|
303
|
+
- [Twitter][twitter]
|
|
304
|
+
- [LinkedIn][linkedin]
|
|
305
|
+
- [dev.to][devto]
|
|
306
|
+
- [Medium][medium]
|
|
307
|
+
- [YouTube][youtube]
|
|
308
|
+
- [HackerNews][hackernews]
|
|
309
|
+
- [Product Hunt][producthunt]
|
|
310
|
+
|
|
311
|
+
# :clap: Our Supporters
|
|
312
|
+
|
|
313
|
+
[](https://github.com/rudderlabs/gatsby-plugin-rudderstack/stargazers)
|
|
314
|
+
[](https://github.com/rudderlabs/gatsby-plugin-rudderstack/network/members)
|
|
315
|
+
|
|
316
|
+
<!----variables---->
|
|
317
|
+
|
|
318
|
+
[slack]: https://resources.rudderstack.com/join-rudderstack-slack
|
|
319
|
+
[twitter]: https://twitter.com/rudderstack
|
|
320
|
+
[linkedin]: https://www.linkedin.com/company/rudderlabs/
|
|
321
|
+
[devto]: https://dev.to/rudderstack
|
|
322
|
+
[medium]: https://rudderstack.medium.com/
|
|
323
|
+
[youtube]: https://www.youtube.com/channel/UCgV-B77bV_-LOmKYHw8jvBw
|
|
324
|
+
[rudderstack-blog]: https://rudderstack.com/blog/
|
|
325
|
+
[hackernews]: https://news.ycombinator.com/item?id=21081756
|
|
326
|
+
[producthunt]: https://www.producthunt.com/posts/rudderstack
|
|
327
|
+
[agplv3_license]: https://www.gnu.org/licenses/agpl-3.0-standalone.html
|
|
328
|
+
[sspl_license]: https://www.mongodb.com/licensing/server-side-public-license
|
|
329
|
+
[config-generator]: https://github.com/rudderlabs/config-generator
|
|
330
|
+
[config-generator-section]: https://github.com/rudderlabs/rudder-server/blob/master/README.md#rudderstack-config-generator
|
|
331
|
+
[rudder-logo]: https://repository-images.githubusercontent.com/197743848/b352c900-dbc8-11e9-9d45-4deb9274101f
|
|
@@ -0,0 +1,36 @@
|
|
|
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 === void 0 ? 50 : _ref2$trackPageDelay;
|
|
8
|
+
function trackRudderStackPage() {
|
|
9
|
+
if (trackPage) {
|
|
10
|
+
var delay = Math.max(0, trackPageDelay);
|
|
11
|
+
window.setTimeout(function () {
|
|
12
|
+
window.rudderanalytics && window.rudderanalytics.page(document.title);
|
|
13
|
+
}, delay);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (window.rudderSnippetLoaded === false) {
|
|
17
|
+
if (window.rudderSnippetLoading === true) {
|
|
18
|
+
window.rudderSnippetLoadedCallback = function () {
|
|
19
|
+
trackRudderStackPage();
|
|
20
|
+
};
|
|
21
|
+
} else {
|
|
22
|
+
if (prevLocation) {
|
|
23
|
+
window.rudderSnippetLoadedCallback = undefined;
|
|
24
|
+
window.rudderSnippetLoader(function () {
|
|
25
|
+
trackRudderStackPage();
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
window.rudderSnippetLoadedCallback = function () {
|
|
29
|
+
trackRudderStackPage();
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
trackRudderStackPage();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports.onPreInit = () => console.log("Loaded gatsby-plugin-rudderstack");
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = _interopRequireDefault(require("react"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
5
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
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; }
|
|
8
|
+
exports.onRenderBody = function (_ref, pluginOptions) {
|
|
9
|
+
var setHeadComponents = _ref.setHeadComponents;
|
|
10
|
+
var prodKey = pluginOptions.prodKey,
|
|
11
|
+
devKey = pluginOptions.devKey,
|
|
12
|
+
_pluginOptions$dataPl = pluginOptions.dataPlaneUrl,
|
|
13
|
+
dataPlaneUrl = _pluginOptions$dataPl === void 0 ? "https://hosted.rudderlabs.com" : _pluginOptions$dataPl,
|
|
14
|
+
controlPlaneUrl = pluginOptions.controlPlaneUrl,
|
|
15
|
+
delayLoad = pluginOptions.delayLoad,
|
|
16
|
+
delayLoadTime = pluginOptions.delayLoadTime,
|
|
17
|
+
manualLoad = pluginOptions.manualLoad,
|
|
18
|
+
loadType = pluginOptions.loadType,
|
|
19
|
+
_pluginOptions$sdkURL = pluginOptions.sdkURL,
|
|
20
|
+
sdkURL = _pluginOptions$sdkURL === void 0 ? "https://cdn.rudderlabs.com/beta/3.0.0-beta" : _pluginOptions$sdkURL,
|
|
21
|
+
_pluginOptions$loadOp = pluginOptions.loadOptions,
|
|
22
|
+
loadOptions = _pluginOptions$loadOp === void 0 ? {} : _pluginOptions$loadOp,
|
|
23
|
+
useLegacySDK = pluginOptions.useLegacySDK;
|
|
24
|
+
|
|
25
|
+
if (!prodKey || prodKey.length < 10) console.error("Your RudderStack prodKey must be at least 10 char in length.");
|
|
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
|
+
|
|
31
|
+
var finalLoadOptions = _objectSpread(_objectSpread({}, loadOptions), {}, {
|
|
32
|
+
configUrl: controlPlaneUrl || loadOptions.configUrl
|
|
33
|
+
});
|
|
34
|
+
var loadConfig = "'".concat(writeKey, "', '").concat(dataPlaneUrl, "', ").concat(JSON.stringify(finalLoadOptions));
|
|
35
|
+
var snippet = "var sdkBaseUrl=\"".concat(sdkURL, "\";var sdkName=\"rsa.min.js\";var asyncScript=true;window.rudderAnalyticsBuildType=\"legacy\",window.rudderanalytics=[];\n var e=[\"setDefaultInstanceKey\",\"load\",\"ready\",\"page\",\"track\",\"identify\",\"alias\",\"group\",\"reset\",\"getAnonymousId\",\"setAnonymousId\",\"startSession\",\"endSession\",\"getSessionId\"];\n for(var n=0;n<e.length;n++){var d=e[n];window.rudderanalytics[d]=function(e){return function(){window.rudderanalytics.push([e].concat(Array.prototype.slice.call(arguments)))}}(d)}\n try{new Function('return import(\"\")'),window.rudderAnalyticsBuildType=\"modern\"}catch(a){}\n if(window.rudderAnalyticsMount=function(){var e=document.createElement(\"script\");e.src=\"\".concat(sdkBaseUrl,\"/\").concat(window.rudderAnalyticsBuildType,\"/\").concat(sdkName),e.async=asyncScript,document.head?document.head.appendChild(e):document.body.appendChild(e)},\"undefined\"==typeof Promise){var t=document.createElement(\"script\");\n t.src=\"https://polyfill.io/v3/polyfill.min.js?features=globalThis%2CPromise&callback=rudderAnalyticsMount\",t.async=asyncScript,document.head?document.head.appendChild(t):document.body.appendChild(t)}else{window.rudderAnalyticsMount()");
|
|
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
|
+
}
|
|
46
|
+
var instantLoader = "".concat(snippet).concat(manualLoad ? "" : "rudderanalytics.load(".concat(loadConfig, ")"), ";");
|
|
47
|
+
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
|
+
var snippetToUse = "".concat(delayLoad && !manualLoad ? delayedLoader : instantLoader);
|
|
50
|
+
|
|
51
|
+
if (writeKey) {
|
|
52
|
+
var tags = [_react["default"].createElement("script", {
|
|
53
|
+
key: "plugin-rudderstack",
|
|
54
|
+
dangerouslySetInnerHTML: {
|
|
55
|
+
__html: snippetToUse
|
|
56
|
+
}
|
|
57
|
+
})];
|
|
58
|
+
setHeadComponents(tags);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gatsby-plugin-rudderstack",
|
|
3
|
+
"version": "3.0.0-beta.0",
|
|
4
|
+
"description": "Event tracking with RudderStack in your Gatsby frontend.",
|
|
5
|
+
"main": "gatsby-ssr.js",
|
|
6
|
+
"scripts": {
|
|
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/"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/rudderlabs/gatsby-plugin-rudderstack.git"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"rudderstack",
|
|
31
|
+
"rudderstack analytics",
|
|
32
|
+
"event tracking",
|
|
33
|
+
"gatsby",
|
|
34
|
+
"gatsby-plugin"
|
|
35
|
+
],
|
|
36
|
+
"author": "RudderStack",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/rudderlabs/gatsby-plugin-rudderstack/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/rudderlabs/gatsby-plugin-rudderstack#readme",
|
|
42
|
+
"devDependencies": {
|
|
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"
|
|
69
|
+
},
|
|
70
|
+
"eslintConfig": {
|
|
71
|
+
"rules": {
|
|
72
|
+
"strict": "off"
|
|
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"
|
|
97
|
+
}
|
|
98
|
+
}
|