1.2.3 • Published 5 months ago
hardal v1.2.3
Hardal
An official plugin to add the Hardal tracking server-side events to your React or Next.js project.
What is Hardal?
Hardal is a server-side platform for connecting your first-party data from any source to any destination for websites and mobile apps.
Installation
npm install hardal
Usage
First, set up Hardal in your project:
// lib/hardal.ts
import Hardal from '../hardal/index.js'
const isClient = typeof window !== 'undefined';
export const hardal = isClient
? new Hardal({
endpoint: process.env.NEXT_PUBLIC_HARDAL_ENDPOINT,
autoPageview: true,
fetchFromDataLayer: true,
// other options...
})
: null;
// Helper function to safely use hardal
export const track = (eventName: string, properties?: Record<string, any>) => {
if (hardal) {
hardal.track(eventName, properties);
}
};
export default hardal;
Then use it in your components:
"use client"
import { track } from '@/lib/hardal';
export const MyComponent = () => {
const eventHandler = () => {
track('button_click', {
type: 'submit',
page: '/checkout',
package: 'premium',
...// any other properties
});
}
return (
<div>
<button onClick={eventHandler}>Send Event</button>
</div>
)
}
License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Support
- Documentation: https://docs.usehardal.com
- Email: support@usehardal.com