Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dapperlabs/react-analytics

Package Overview
Dependencies
Maintainers
4
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dapperlabs/react-analytics

A utility to connect react projects to segment

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
72
decreased by-23.4%
Maintainers
4
Weekly downloads
 
Created
Source

react-analytics 👩‍🔬

Convenience component for creating a connecting to segment.

Values provided on context:

  • analyticsReady: boolean
  • identify: function
  • trackButtonClick: function
  • trackPageView: function
  • track: function

Provider Props

  • children: the contained react components
  • segmentWriteToken: the segment key

Setup

Import the provider and wrap your application in it.

import { AnalyticsProvider } from '@dapperlabs/react-analytics';

function Root() {
  return (
    <AnalyticsProvider
      clientSideId={process.env.SEGMENT_WRITE_TOKEN}
    >
      <MyDApp />
    </AnalyticsProvider>
  )
}

Context

Context is directly available via import { AnalyticsContext } from '@dapperlabs/react-analytics and can be consumed however you'd like:

  • useContext(AnalyticsContext) 👈IDEAL 😎
  • static contextType = AnalyticsContext
  • <AnalyticsContext.Consumer />
import React, { useContext, useRef } from 'react';
import { AnalyticsContext } from '@dapperlabs/analytics';

function Button({ children, id, onClick, trackingProperties }) {
  const buttonRef = useRef(null);
  const { trackButtonClick } = useContext(AnalyticsContext);

  const handleClick = () => {
    trackButtonClick({
      text: buttonRef.current.innerText || 'BUTTON_HAS_NO_TEXT',
      id: id || 'BUTTON_HAS_NO_ID',
      ...trackingProperties,
    });
    onClick();
  };

  return (
    <button
      ref={buttonRef}
      type="button"
      onClick={handleClick}
      id={id}
    >
      {children}
    </button>
  );
}

FAQs

Package last updated on 16 Aug 2019

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