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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@surveyanalytica/clickstream-rn

v1.0.0

Published

SurveyAnalytica Clickstream SDK for React Native

Readme

@surveyanalytica/clickstream-rn

SurveyAnalytica Clickstream SDK for React Native. Sends behavioral events from your mobile app to the SA workflow engine.

Installation

npm install @surveyanalytica/clickstream-rn @react-native-async-storage/async-storage

For iOS, install native pods:

cd ios && pod install

@react-native-async-storage/async-storage requires no additional native setup on Android.

Quick Start

1. Initialize in App.js

Call SAClickstream.init() once at app startup, before rendering any screens. It returns a Promise — await it or call it fire-and-forget. Events fired before init resolves are buffered automatically.

// App.js
import { useEffect } from 'react';
import { SAClickstream } from '@surveyanalytica/clickstream-rn';

export default function App() {
  useEffect(() => {
    SAClickstream.init(
      'your-workflow-id',
      'your-api-key',
      { saEndpoint: 'https://api.surveyanalytica.com' }
    );
  }, []);

  return <RootNavigator />;
}

2. Track screen views with useSAPage

Drop useSAPage at the top of any screen component. It fires a page_view event when the screen mounts.

// screens/HomeScreen.js
import { View, Text } from 'react-native';
import { useSAPage } from '@surveyanalytica/clickstream-rn';

export default function HomeScreen() {
  useSAPage('Home');

  return (
    <View>
      <Text>Welcome</Text>
    </View>
  );
}

Pass extra properties as the second argument:

useSAPage('ProductDetail', { productId: '123', category: 'shoes' });

3. Track events

import { SAClickstream } from '@surveyanalytica/clickstream-rn';

// Simple event
SAClickstream.track('button_tapped', { buttonId: 'checkout' });

// With properties
SAClickstream.track('product_viewed', {
  productId: 'abc-123',
  price: 49.99,
  currency: 'USD',
});

4. Identify a user

Call identify() after login to associate the session with a known contact. This emits a uid_transition event and flushes any pending queue.

// After successful login
SAClickstream.identify(user.id);

5. Handle deep link contact IDs

If your app receives a deep link containing ?sa_cid=<id> (e.g. from an SA campaign link), pass the extracted value to init():

import { Linking } from 'react-native';

const url = await Linking.getInitialURL();
const saContactId = url ? new URL(url).searchParams.get('sa_cid') : null;

SAClickstream.init('your-workflow-id', 'your-api-key', {
  saEndpoint: 'https://api.surveyanalytica.com',
  deepLinkContactId: saContactId,
});

When a deepLinkContactId differs from the stored identity, the SDK automatically emits a uid_transition event before switching to the new ID.

6. Consent management

// Revoke consent — stops all tracking and clears the pending queue
SAClickstream.setConsent(false);

// Restore consent — tracking resumes
SAClickstream.setConsent(true);

API Reference

SAClickstream.init(workflowId, apiKey, options)Promise<void>

| Parameter | Type | Required | Description | |---|---|---|---| | workflowId | string | Yes | SA workflow ID that receives events | | apiKey | string | Yes | Sent as the code request header | | options.saEndpoint | string | Yes | Base URL of the SA backend | | options.deepLinkContactId | string | No | Contact ID from an incoming deep link |

SAClickstream.track(eventName, properties?)

Track a named behavioral event. properties is an arbitrary key/value object.

SAClickstream.page(screenName, properties?)

Track a screen view manually. Prefer useSAPage in screen components.

SAClickstream.identify(contactId)

Link the anonymous visitor to a known contact ID. Emits uid_transition and flushes the queue.

SAClickstream.setConsent(given)

Pass false to stop all tracking. Pass true to resume.

useSAPage(screenName, properties?)

React hook. Calls SAClickstream.page() on mount. Re-fires if screenName changes.

Behavior Details

  • Identity: Stored in @react-native-async-storage/async-storage under key sa_id. Generated as a UUID v4 on first launch.
  • Batching: Events are batched with a 500 ms debounce, or immediately when 20 events accumulate.
  • Retry: Failed requests are retried up to 3 times with exponential backoff (1s, 2s, 4s).
  • Device info: Uses Platform.OS from react-native. No react-native-device-info dependency.
  • Pre-init buffering: Events fired before init() resolves are buffered in memory and flushed once identity loads.

Peer Dependencies

| Package | Version | |---|---| | react | >=18.0.0 | | react-native | >=0.71.0 | | @react-native-async-storage/async-storage | >=1.18.0 |

License

MIT