@adhawk/analytics-pixel-loader
v2.0.2
Published
A webpack loader which builds Segment analytics.js pixels as small, efficient bundles
Downloads
105
Keywords
Readme
@adhawk/analytics-pixel-loader
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.
Setup
- Install the package
yarn add @adhawk/analytics-pixel-loader- Create an
analytics-pixel.ymlfile 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" })} />Overriding a Page's Analytics Configuration
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"}}'
/>