1.0.0-beta.2 • Published 2 years ago
@hexatool/google-tag v1.0.0-beta.2
Installation
npm install --save @hexatool/google-tag
Using bun
bun add @hexatool/google-tag
Using yarn
yarn add @hexatool/google-tag
Using pnpm
pnpm add @hexatool/google-tag
How to use
See full documentation here.
import { GoogleTag } from "@hexatool/google-tag";
const gtag = new GoogleTag("G-XXXXXXXXXX");
// Loads Google Tag script
gtag.initialize();
// Sends a page view event
gtag.event("page_view", {
page_title: "Home",
page_location: "https://example.com",
});
gtag.destroy();
Using with React
import { useGoogleTag } from '@hexatool/google-tag/react';
const App = () => {
const gtag = useGoogleTag('G-XXXXXXXXXX');
useEffect(() => {
gtag.initialize();
}, []);
const handleClick = () => {
...
gtag.event('click', { category: 'button', label: 'Lorem ipsum' });
};
return (
<main>
<h1>Lorem ipsum</h1>
<button onClick={handleClick}>
Click me
</button>
</main>
);
};
Hexatool Code Quality Standards
Publishing this package we are committing ourselves to the following code quality standards:
- Respect Semantic Versioning: No breaking changes in patch or minor versions
- No surprises in transitive dependencies: Use the bare minimum dependencies needed to meet the purpose
- One specific purpose to meet without having to carry a bunch of unnecessary other utilities
- Tests as documentation and usage examples
- Well documented README showing how to install and use
- License favoring Open Source and collaboration