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

@referrals/referagent

v1.0.2

Published

Official ReferAgent SDK for Next.js - Easy referral campaign tracking and management

Readme

@referrals/referagent

npm version License: MIT

Official SDK for integrating ReferAgent referral tracking into your Next.js application. Build powerful referral campaigns with just a few lines of code.

Installation

npm install @referrals/referagent
# or
pnpm add @referrals/referagent
# or
yarn add @referrals/referagent

Quick Start

1. Setup Provider

Wrap your app with the ReferAgentProvider:

// app/layout.tsx
import { ReferAgentProvider } from "@referrals/referagent/react"

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        <ReferAgentProvider config={{ apiKey: process.env.REFERAGENT_API_KEY! }}>
          {children}
        </ReferAgentProvider>
      </body>
    </html>
  )
}

2. Use Referral Links

import { ReferralLink } from "@referrals/referagent/react"

export default function HomePage() {
  return (
    <ReferralLink campaignId="camp_123" alias="SUMMER2024">
      <button>Share with Friends</button>
    </ReferralLink>
  )
}

3. Track Conversions

import { useReferAgent } from "@referrals/referagent/react"

export default function CheckoutPage() {
  const client = useReferAgent()
  const code = "SUMMER2024" // Get from URL params or cookies

  const handlePurchase = async () => {
    // Your purchase logic...
    
    // Track conversion
    await client.trackConversion({
      code,
      value: 99.99,
      metadata: { plan: "pro" },
    })
  }

  return <button onClick={handlePurchase}>Complete Purchase</button>
}

AI Features

The SDK includes powerful AI-powered features to help optimize your referral campaigns:

Campaign Suggestions

const suggestions = await client.aiGetCampaignSuggestions("domain_123")
// Returns: Array of campaign suggestions with confidence scores

Link Optimization

// Optimize new link aliases
const optimizations = await client.aiOptimizeLink("campaign_123")

// Analyze existing link performance
const analysis = await client.aiOptimizeLink("campaign_123", "link_456")

Timing Optimization

const timing = await client.aiGetTimingOptimization("campaign_123")
// Returns: Best times to share, optimal duration, seasonal trends

Strategy Recommendations

const strategy = await client.aiGetStrategyRecommendations("campaign_123")
// Returns: Insights, recommendations, opportunities, risks, next steps

Performance Prediction

const prediction = await client.aiPredictPerformance("campaign_123", 30)
// Returns: Projected clicks, conversions, revenue for next 30 days

Personal Recommendations

const recommendations = await client.aiGetPersonalRecommendations()
// Returns: Personalized recommendations based on your account performance

API Reference

ReferAgent Client

import ReferAgent from "@referrals/referagent"

const client = new ReferAgent({
  apiKey: "your-api-key",
  baseUrl: "https://api.referagent.com", // optional
})

Methods

Campaign Management

  • campaignsCreate(data) - Create a new campaign
  • campaignsList() - List all campaigns
  • campaignsGet(id) - Get campaign by ID

Link Management

  • linksCreate(campaignId, alias?) - Create a referral link
  • trackClick(options) - Track a click event
  • trackConversion(options) - Track a conversion event

AI-Powered Features

  • aiGetCampaignSuggestions(domainId) - Get AI-powered campaign suggestions
  • aiOptimizeLink(campaignId, linkId?) - Optimize link alias or analyze link performance
  • aiGetTimingOptimization(campaignId) - Get optimal timing recommendations
  • aiGetStrategyRecommendations(campaignId) - Get strategic recommendations
  • aiPredictPerformance(campaignId, days?) - Predict campaign performance
  • aiGetPersonalRecommendations() - Get personalized recommendations

React Components & Hooks

<ReferralLink>

Automatically generates and wraps content with a referral link.

<ReferralLink campaignId="camp_123" alias="SUMMER2024">
  Share Now
</ReferralLink>

useReferAgent()

Access the ReferAgent client instance.

const client = useReferAgent()
const link = await client.linksCreate("camp_123")

useReferralTracking()

Automatic click tracking hook.

const { trackClick } = useReferralTracking({
  code: "SUMMER2024",
  autoTrack: true,
})

TypeScript Support

This package includes TypeScript definitions. No additional @types package needed.

Requirements

  • Node.js 18+
  • React 18+ (for React components)
  • Next.js 16+ (recommended, but not required)

Error Handling

All SDK methods throw errors that you can catch:

try {
  const campaign = await client.campaignsCreate({
    name: "My Campaign",
    targetUrl: "https://example.com",
  })
} catch (error) {
  console.error("Failed to create campaign:", error.message)
}

Rate Limiting

The SDK automatically handles rate limiting. If you hit rate limits, the API will return a 429 status code with retry information.

Contributing

Contributions are welcome! Please read our contributing guidelines first.

Support

License

MIT © ReferAgent