New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@goodhood/helpers

Package Overview
Dependencies
Maintainers
6
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@goodhood/helpers

shared helpers for Good Hood applications

  • 1.0.0-beta.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created
Source

@goodhood/tracking

Declarative tracking for react apps

Split up tracking payload setup from the actual tracking call. Avoids leaking data across the whole app.

  • Preview

Install

npm i @goodhood/tracking
import { TrackingProvider } from '@goodhood/tracking';

const handleEvent = (payload) => {
  sendAnalyticsEvent(payload);
};

<TrackingProvider onEvent={handleEvent}>
  ...
</TrackingProvider>

Preview

Usage

Track an event with hooks

trackingProvider.track(payload)

  • sends the payload to the parent provider
  • expects an object
    • with at least the event key
    • can have any kind of other keys

useTrack returns a function that forwards to trackingProvider.track(payload)

import { useTrack } from '@goodhood/tracking';

export default {
    const track = useTrack();

    return (
      <button 
        type="button"
        onClick={() => { track({ event: 'button-clicked' }); }}
      >
        track now
      </button>
    );
}

Track an event via class components


class ClassComponent extends PureComponent {
  constructor(props) {
    super(props);
    this.handleClick = this.handleClick.bind(this);
  }

  handleClick() {
    this.provider.track({ event: 'button-clicked' });
  }

  render() {
    return (
      <>
        <Provider ref={(provider) => { this.provider = provider; }} />
        <button type="button" onClick={this.handleClick} className="ui-button ui-button-primary">
          press me to track (check console)
        </button>
      </>
    );
  }
}

Track on mount

TrackingTrigger accepts any kind of props. All props will be forwarded as payload to track(payload).

import { TrackingTrigger } from '@goodhood/tracking';

<TrackingTrigger event="pageload" additional-data={123} />

Setting up tracking data

<Provider email="fun@mail.at">
  <Provider funnel="Post creation" any-kind-of-prop="oh yes">
    <TrackButton />
  </Provider>
</Provider>

TrackingProvider

TrackingProvider accepts the following props:

  • onEvent: Called whenever the provider receives a track(payload) call. Either directly or coming from a TrackingProvider inside children.
  • transform: Allows to change payloads before they are sent to the parent TrackingProvider (or to onEvent) (check stories for detailed examples)
  • all other props will be merged to the payload

TrackingProvider allows imperative access to:

  • track(payload) as described above

FAQs

Package last updated on 19 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc