This packages export a React component which will wrap React components to catch errors. A user is shown a dialog to give feedback when they experience an error.
- Install the package
yarn add @adhawk/analytics-pixel-loader
- Create an
analytics-pixel.yml
file with your Segment config
---
- name: Google Analytics
opts:
trackingId: UA-123
sendUserId: true
- Setup webpack loader to build the pixel
module: {
rules: [
{
test: /analytics-pixel\.yml$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "@adhawk/analytics-pixel-loader",
},
},
];
}
- Import the analytics pixel in your main entrypoint:
// index.js
import "./analytics-pixel.yml";
- Start tracking
<button onClick={() => analytics.track("Button Clicked", { foo: "bar" })} />
To override an analytics configuration for a page, simply add a meta tag with the JSON you would like to use as the configuration:
<meta
name="analytics-config"
content='{"Google Analytics": {"trackingId": "123"}}'
/>