gatsby-plugin-rudderstack 2.0.0 → 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/ISSUE_TEMPLATE/bug_report.md +39 -0
- package/.github/ISSUE_TEMPLATE/feature-request.md +20 -0
- package/.github/pull_request_template.md +13 -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 -0
- package/CODE_OF_CONDUCT.md +80 -0
- package/CONTRIBUTING.md +47 -0
- package/commitlint.config.js +3 -0
- package/dist/LICENSE.md +21 -0
- package/dist/README.md +331 -0
- package/dist/gatsby-node.js +1 -0
- package/{gatsby-ssr.js → dist/gatsby-ssr.js} +13 -9
- package/dist/package.json +98 -0
- package/package.json +1 -1
- package/sonar-project.properties +35 -0
- package/CHANGELOG.md +0 -14
- /package/{gatsby-browser.js → dist/gatsby-browser.js} +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
name: 'Unit Tests, Coverage & Sonar'
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
push:
|
|
6
|
+
branches: ['main', 'develop']
|
|
7
|
+
pull_request:
|
|
8
|
+
branches: ['main', 'develop']
|
|
9
|
+
types: ['opened', 'reopened', 'synchronize']
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
build:
|
|
13
|
+
name: 'Unit Tests, Coverage & Sonar'
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- name: Checkout
|
|
18
|
+
uses: actions/checkout@v3
|
|
19
|
+
with:
|
|
20
|
+
fetch-depth: 0
|
|
21
|
+
|
|
22
|
+
- name: Setup Node
|
|
23
|
+
uses: actions/setup-node@v3
|
|
24
|
+
with:
|
|
25
|
+
node-version-file: '.nvmrc'
|
|
26
|
+
cache: 'npm'
|
|
27
|
+
|
|
28
|
+
- name: Execute unit tests
|
|
29
|
+
env:
|
|
30
|
+
HUSKY: 0
|
|
31
|
+
run: |
|
|
32
|
+
npm ci
|
|
33
|
+
npm run test:ci
|
|
34
|
+
npm run check:lint:ci
|
|
35
|
+
|
|
36
|
+
- name: Fix filesystem paths in generated reports
|
|
37
|
+
run: |
|
|
38
|
+
sed -i 's+/home/runner/work/gatsby-plugin-rudderstack/gatsby-plugin-rudderstack+/github/workspace+g' reports/eslint.json
|
|
39
|
+
|
|
40
|
+
- name: SonarCloud Scan
|
|
41
|
+
uses: SonarSource/sonarcloud-github-action@master
|
|
42
|
+
env:
|
|
43
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
44
|
+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="JAVA_MODULE" version="4">
|
|
3
|
+
<component name="Go" enabled="true" />
|
|
4
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
5
|
+
<exclude-output />
|
|
6
|
+
<content url="file://$MODULE_DIR$" />
|
|
7
|
+
<orderEntry type="inheritedJdk" />
|
|
8
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
9
|
+
</component>
|
|
10
|
+
</module>
|
package/.idea/misc.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/gatsby-plugin-rudderstack.iml" filepath="$PROJECT_DIR$/.idea/gatsby-plugin-rudderstack.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
package/.idea/vcs.xml
ADDED
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
16.15.1
|
package/.prettierignore
ADDED
package/.prettierrc
ADDED
package/CODEOWNERS
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
|
9
|
+
level of experience, education, socio-economic status, nationality, personal
|
|
10
|
+
appearance, race, religion, or sexual identity and orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at **contact@rudderstack.com**. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [https://www.contributor-covenant.org][contributor-covenant].
|
|
72
|
+
|
|
73
|
+
For answers to common questions about this code of conduct, see the [FAQs][faqs].
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
<!-----variables---->
|
|
77
|
+
|
|
78
|
+
[homepage]: https://www.contributor-covenant.org
|
|
79
|
+
[contributor-covenant]: https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
|
80
|
+
[faqs]: https://www.contributor-covenant.org/faq
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Contributing to RudderStack #
|
|
2
|
+
|
|
3
|
+
Thanks for taking the time and for your help improving this project!
|
|
4
|
+
|
|
5
|
+
## Getting Help ##
|
|
6
|
+
|
|
7
|
+
If you have a question about rudder or have encountered problems using it,
|
|
8
|
+
start by asking a question on [Slack][slack].
|
|
9
|
+
|
|
10
|
+
## Rudder Labs Contributor Agreement ##
|
|
11
|
+
|
|
12
|
+
To contribute to this project, we need you to sign to [Contributor License Agreement (“CLA”)][CLA] for the first commit you make. By agreeing to the [CLA][CLA]
|
|
13
|
+
we can add you to list of approved contributors and review the changes proposed by you.
|
|
14
|
+
|
|
15
|
+
## Installing and Setting Up \*\* Software Name \*\*
|
|
16
|
+
|
|
17
|
+
\*\* Describe, in detail, how to setup and start using the software. \*\*
|
|
18
|
+
|
|
19
|
+
## Submitting a Pull Request ##
|
|
20
|
+
|
|
21
|
+
Do you have an improvement?
|
|
22
|
+
|
|
23
|
+
1. Submit an [issue][issue] describing your proposed change.
|
|
24
|
+
2. We will try to respond to your issue promptly.
|
|
25
|
+
3. Fork this repo, develop and test your code changes. See the project's [README](README.md) for further information about working in this repository.
|
|
26
|
+
4. Submit a pull request against this repo's `main` branch.
|
|
27
|
+
- Include instructions on how to test your changes.
|
|
28
|
+
5. Your branch may be merged once all configured checks pass, including:
|
|
29
|
+
- A review from appropriate maintainers
|
|
30
|
+
|
|
31
|
+
## Committing ##
|
|
32
|
+
|
|
33
|
+
We prefer squash or rebase commits so that all changes from a branch are
|
|
34
|
+
committed to master as a single commit. All pull requests are squashed when
|
|
35
|
+
merged, but rebasing prior to merge gives you better control over the commit
|
|
36
|
+
message.
|
|
37
|
+
|
|
38
|
+
We look forward to your feedback on improving this project.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
<!----variable's---->
|
|
42
|
+
|
|
43
|
+
\*\* Update variable links. \*\*
|
|
44
|
+
|
|
45
|
+
[slack]: https://resources.rudderstack.com/join-rudderstack-slack
|
|
46
|
+
[issue]: https://github.com/rudderlabs/rudder-repo-template/issues/new
|
|
47
|
+
[CLA]: https://rudderlabs.wufoo.com/forms/rudderlabs-contributor-license-agreement
|
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 @@
|
|
|
1
|
+
exports.onPreInit = () => console.log("Loaded gatsby-plugin-rudderstack");
|
|
@@ -17,9 +17,10 @@ exports.onRenderBody = function (_ref, pluginOptions) {
|
|
|
17
17
|
manualLoad = pluginOptions.manualLoad,
|
|
18
18
|
loadType = pluginOptions.loadType,
|
|
19
19
|
_pluginOptions$sdkURL = pluginOptions.sdkURL,
|
|
20
|
-
sdkURL = _pluginOptions$sdkURL === void 0 ? "https://cdn.rudderlabs.com/
|
|
20
|
+
sdkURL = _pluginOptions$sdkURL === void 0 ? "https://cdn.rudderlabs.com/beta/3.0.0-beta" : _pluginOptions$sdkURL,
|
|
21
21
|
_pluginOptions$loadOp = pluginOptions.loadOptions,
|
|
22
|
-
loadOptions = _pluginOptions$loadOp === void 0 ? {} : _pluginOptions$loadOp
|
|
22
|
+
loadOptions = _pluginOptions$loadOp === void 0 ? {} : _pluginOptions$loadOp,
|
|
23
|
+
useLegacySDK = pluginOptions.useLegacySDK;
|
|
23
24
|
|
|
24
25
|
if (!prodKey || prodKey.length < 10) console.error("Your RudderStack prodKey must be at least 10 char in length.");
|
|
25
26
|
|
|
@@ -31,14 +32,17 @@ exports.onRenderBody = function (_ref, pluginOptions) {
|
|
|
31
32
|
configUrl: controlPlaneUrl || loadOptions.configUrl
|
|
32
33
|
});
|
|
33
34
|
var loadConfig = "'".concat(writeKey, "', '").concat(dataPlaneUrl, "', ").concat(JSON.stringify(finalLoadOptions));
|
|
34
|
-
var
|
|
35
|
-
if (
|
|
36
|
-
scriptTagStr
|
|
37
|
-
|
|
38
|
-
|
|
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);
|
|
39
45
|
}
|
|
40
|
-
scriptTagStr += "document.head.appendChild(s);";
|
|
41
|
-
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 ".concat(scriptTagStr, "\n");
|
|
42
46
|
var instantLoader = "".concat(snippet).concat(manualLoad ? "" : "rudderanalytics.load(".concat(loadConfig, ")"), ";");
|
|
43
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 ");
|
|
44
48
|
|