A Greenwood plugin adding support for Google Analytics JavaScript tracker. It assumes you already have your own Tracking ID(s) and can either filter out tracking for everything but your production environment so that local testing doesn't interfere with production data, or use a conditional based analyticsId
using an environment variable, ex.
const analyticsId = process.env.NODE_ENV === 'xxx' ? 'UA-123...' : 'UA-345...';
For more information and complete docs about Greenwood, please visit the Greenwood website.
You can use your favorite JavaScript package manager to install this package. This package assumes you already have @greenwood/cli
installed.
examples:
# npm
npm install @greenwood/plugin-google-analytics --save-dev
# yarn
yarn add @greenwood/plugin-google-analytics --dev
Use this plugin in your greenwood.config.js and pass in your Google Analytics ID, which can either be a
- Measurement ID (recommended): ex.
G-XXXXXX
- Tracking ID (legacy): ex.
UA-XXXXXX
import { greenwoodPluginGoogleAnalytics } from '@greenwood/plugin-google-analytics';
export default {
...
plugins: [
greenwoodPluginGoogleAnalytics({
analyticsId: 'UA-XXXXXX'
})
]
}
This will then add the Google Analytics JavaScript tracker snippet to your project's index.html.
Learn more about Measurement and Tracking IDs.
-
analyticsId
(required) - Your Google Analytics ID -
anonymous
(optional) - Sets if tracking of IPs should be done anonymously. Default istrue
For links that go outside of your domain, the global function getOutboundLink
is available for you to use.
Example:
<a
target="_blank"
rel="noopener"
onclick="getOutboundLink('www.mylink.com');"
href="www.mylink.com">My Link
</a>