npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pollinginc/polling-react-sdk

v1.0.10

Published

React JS SDK Wrapper to intereact with Polling.com services

Downloads

136

Readme

@pollinginc/polling-react-sdk

Introduction

This is a React library for interacting with Polling.com services, which was created on top of our vanilla JS library.

This SDK allows you to send events, log purchases, and display embedded survey pages or show a specific survey seamlessly within your React application.

Installation

To install the SDK, run the following command:

npm install @pollinginc/polling-react-sdk

Usage

Getting Started

Before starting, you will need to obtain an API key from Polling.com, the API key links your integration to a embed on the Polling.com platform.

You will also need to provide a Customer ID (your customer), which is your unique identifier for the user on your application, we'll use this to link them to their surveys and events inside Polling.com.

Provider Usage

Wrap your application or the parent component with the PollingSDKProvider to initialize the SDK and provide the context methods to your children components. Required props are apiKey and customerId.

import React from 'react';
import ReactDOM from 'react-dom';
import { PollingSDKProvider } from '@pollinginc/polling-react-sdk';

const App = () => (
    <PollingSDKProvider apiKey="your-api-key" customerId="your-customer-unique-id">
        <YourComponent />
    </PollingSDKProvider>
);

ReactDOM.render(<App />, document.getElementById('root'));

Hook Usage

Use the usePollingSDK hook to access the SDK methods within your components.

Available methods are

  • logSession() - Logs a simple Session event for the given user
  • logPurchase(cents: number) - Logs a Purchase event for the given user with the amount in cents
  • logEvent(eventName: string, eventValue?: string | number) - Sends a custom event name and value - NOTE: This method is only available for Business+ plans.
  • showEmbedView() - Opens the Polling.com embed view popup, which will show the user's surveys (list of surveys, random or a fixed survey depending on the user's settings)
  • showSurvey(surveyUiid: string) - Opens a popup with a specific survey by its UUID
  • setApiKey(apiKey: string) - Changes the API key on the fly, useful if you want to handle multiple embeds with a single SDK instance
  • setCustomerId(customerId: string) - Changes the Customer ID on the fly
import React from 'react';
import { usePollingSDK } from '@pollinginc/polling-react-sdk';

const YourComponent = () => {
    const { logSession, logPurchase, logEvent, showEmbedView, showSurvey } = usePollingSDK();

    const handleLogSession = () => {
        logSession();
    };

    const handleLogPurchase = () => {
        logPurchase(1000); // Log a purchase of 10 usd (1000 cents)
    };

    const handleLogEvent = async () => {
        await logEvent('My Custom Event', 'My Nice Value');
    };

    const handleShowEmbedView = () => {
        showEmbedView();
    };

    const handleShowSurvey = () => {
        showSurvey('survey-uuid');
    };

    return (
        <div>
            <button onClick={handleLogSession}>Log Session</button>
            <button onClick={handleLogPurchase}>Log Purchase</button>
            <button onClick={handleLogEvent}>Log Event</button>
            <button onClick={handleShowEmbedView}>Show Embed View</button>
            <button onClick={handleShowSurvey}>Show Survey</button>
        </div>
    );
};

export default YourComponent;