Identified widget
The campaign knows which signed-in customer completed a donation.
Guide · Next.js
App RouterStart with a public campaign and no credentials. Add customer identity and entitlement gates when your product is ready for them.
A published campaign can be embedded without a developer project, API keys, or changes to your authentication.
pnpm add @our-impact/browser"use client";
import { useEffect, useRef } from "react";
import { mountCampaign } from "@our-impact/browser";
export function CommunityCampaign({ publicId }: { publicId: string }) {
const target = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!target.current) return;
const campaign = mountCampaign({
target: target.current,
publicId,
height: "auto",
});
return () => campaign.destroy();
}, [publicId]);
return <div ref={target} />;
}The campaign knows which signed-in customer completed a donation.
A verified PayPal capture becomes a project event and evaluates entitlement rules.
The Next.js app checks a stable entitlement key before showing a benefit.
The workspace owns both the community campaigns and developer projects used by your application.
Invite each recipient to connect its own PayPal account, then wait until it is ready to receive.
Choose its recipients, schedule, voting behavior, and commitment. Copy the public embed URL.
Add your Next.js origin, then copy the publishable key and the one-time server secret.
Give it a stable key such as community_champion and add an earning path such as “lifetime donations of at least $50.”
pnpm add @our-impact/node @our-impact/browserOUR_IMPACT_SECRET_KEY=oi_sk_test_...
NEXT_PUBLIC_OUR_IMPACT_PUBLISHABLE_KEY=oi_pk_test_...
NEXT_PUBLIC_OUR_IMPACT_CAMPAIGN_ID=your-campaign-idimport "server-only";
import { OurImpactClient } from "@our-impact/node";
export const ourImpact = new OurImpactClient({
secretApiKey: process.env.OUR_IMPACT_SECRET_KEY,
});This Server Component uses the application’s existing session. The stable application user ID becomes the supporter ID inside this developer project.
import { redirect } from "next/navigation";
import { auth } from "@/lib/auth";
import { ourImpact } from "@/lib/our-impact/server";
import { CommunityProgram } from "@/components/community-program";
export default async function CommunityPage() {
const session = await auth();
if (!session?.user?.id) redirect("/login");
const identity = await ourImpact.identity.createIdentityToken({
body: {
externalUserId: session.user.id,
displayName: session.user.name ?? undefined,
ttlSeconds: 900,
},
});
return (
<CommunityProgram
userToken={identity.token}
publishableKey={process.env.NEXT_PUBLIC_OUR_IMPACT_PUBLISHABLE_KEY!}
campaignId={process.env.NEXT_PUBLIC_OUR_IMPACT_CAMPAIGN_ID!}
/>
);
}The same short-lived token powers both the hosted campaign and browser entitlement reads. The SDK creates the iframe, identifies the supporter, removes nested scrolling, and refreshes entitlements after a completed donation.
"use client";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { OurImpact } from "@our-impact/browser";
export function CommunityProgram({
userToken,
publishableKey,
campaignId,
}: {
userToken: string;
publishableKey: string;
campaignId: string;
}) {
const campaignTarget = useRef<HTMLDivElement>(null);
const [isChampion, setIsChampion] = useState(false);
const impact = useMemo(
() => new OurImpact({ publishableKey, userToken }),
[publishableKey, userToken],
);
const refreshAccess = useCallback(async () => {
await impact.refresh();
setIsChampion(await impact.user.is("community_champion"));
}, [impact]);
useEffect(() => { void refreshAccess(); }, [refreshAccess]);
useEffect(() => {
if (!campaignTarget.current) return;
const widget = impact.widgets.mountCampaign({
target: campaignTarget.current,
publicId: campaignId,
height: "auto",
onDonationCompleted() {
void impact.user.is("community_champion").then(setIsChampion);
},
});
return () => widget.destroy();
}, [campaignId, impact]);
return (
<main data-community-champion={isChampion || undefined}>
<div ref={campaignTarget} />
{isChampion ? <ChampionExperience /> : <StandardExperience />}
<button onClick={() => void refreshAccess()}>Refresh benefits</button>
</main>
);
}For authorization—not just visual personalization—query with the secret SDK before rendering or mutating protected data.
const result = await ourImpact.entitlements.listUserEntitlements({
externalUserId: session.user.id,
});
const canAccess = result.entitlements.some(
(item) => item.entitlementKey === "community_champion"
&& item.state === "active",
);
if (!canAccess) redirect("/community");PayPal capture completes inside the campaign widget. Our Impact records the donation against the campaign and recipient, then creates donation.completed for the identified supporter in this developer project.
The project evaluates every matching entitlement rule. A subsequent browser impact.refresh(), server render, or server entitlement query returns the new state.