Skip to content

Commit c362463

Browse files
mueschaLekoArts
andauthored
chore(docs): google plugin analytics - upgrade to gtag, fix code (#28918)
Co-authored-by: LekoArts <[email protected]>
1 parent 4798257 commit c362463

File tree

1 file changed

+15
-7
lines changed
  • packages/gatsby-plugin-google-analytics

1 file changed

+15
-7
lines changed

packages/gatsby-plugin-google-analytics/README.md

+15-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Easily add Google Analytics to your Gatsby site.
44

5+
## Upgrade note
6+
7+
This plugin uses Google's `analytics.js` file under the hood. Google has a [guide recommending users upgrade to `gtag.js` instead](https://developers.google.com/analytics/devguides/collection/upgrade/analyticsjs). There is another plugin [`gatsby-plugin-gtag`](https://gatsbyjs.com/plugins/gatsby-plugin-google-gtag/) which uses `gtag.js`.
8+
59
## Install
610

711
`npm install gatsby-plugin-google-analytics`
@@ -60,13 +64,15 @@ To use it, simply import it and use it like you would the `<a>` element e.g.
6064
import React from "react"
6165
import { OutboundLink } from "gatsby-plugin-google-analytics"
6266

63-
export default () => (
67+
const Component = () => (
6468
<div>
65-
<OutboundLink href="https://www.gatsbyjs.org/packages/gatsby-plugin-google-analytics/">
69+
<OutboundLink href="https://www.gatsbyjs.com/plugins/gatsby-plugin-google-analytics/">
6670
Visit the Google Analytics plugin page!
6771
</OutboundLink>
6872
</div>
6973
)
74+
75+
export default Component
7076
```
7177

7278
## Options
@@ -164,10 +170,10 @@ To allow custom events to be tracked, the plugin exposes a function to include i
164170
To use it, import the package and call the event within your components and business logic.
165171

166172
```jsx
167-
import React
168-
import { trackCustomEvent } from 'gatsby-plugin-google-analytics'
173+
import React from "react"
174+
import { trackCustomEvent } from "gatsby-plugin-google-analytics"
169175

170-
export default () => {
176+
const Component = () => (
171177
<div>
172178
<button
173179
onClick={e => {
@@ -182,15 +188,17 @@ export default () => {
182188
// string - optional - Useful for categorizing events (e.g. 'Spring Campaign')
183189
label: "Gatsby Plugin Example Campaign",
184190
// number - optional - Numeric value associated with the event. (e.g. A product ID)
185-
value: 43
191+
value: 43,
186192
})
187193
//... Other logic here
188194
}}
189195
>
190196
Tap that!
191197
</button>
192198
</div>
193-
}
199+
)
200+
201+
export default Component
194202
```
195203

196204
### All Fields Options

0 commit comments

Comments
 (0)