Installation
Installing ShareCount with an AI coding agent
Copy-pasteable instructions for Claude, Cursor, Copilot, or any agent. Includes invariants, the exact snippet, and a verification step.
This article is written for AI coding agents. Hit the Copy for agentsbutton above to drop it straight into your agent’s context, or paste any of the snippets below into the relevant file.
What you’re installing
- One snippet — a mount node and an async script tag. The script does not block render.
- One public key — looks like
sc_pk_…. Safe to ship to the browser. The user gets it from the dashboard. - Optional: a custom trigger — for SDK mode, a click handler that calls
window.ShareCount.open().
Invariants the agent must preserve
- Do not bundle the script. Always load it from
https://www.sharecount.app/embed.jsso updates ship without a redeploy. - Mount node must be a direct childof whatever container the user wants the bar in. Don’t nest it inside a
<p>or other inline element. - Do not strip the
data-sharecountattribute. The embed scans for it on every DOM mutation. - Do not load multiple copies of the script. One tag per page; the embed coalesces mounts.
- Do not override the script’s URL host unless the user explicitly tells you to (the embed derives the backend origin from its own
src).
Choose the right method
- 1If a pricing page exists, install the Inline Bar immediately above the pricing grid. This is the canonical placement.
- 2If the user wants a custom button (hero CTA, in-app menu, post-signup nudge), install the Custom Trigger snippet and wire their existing button to
window.ShareCount.open(). Tell the user to switch the dashboard mode to Custom Trigger so the teaser disappears. - 3If the user wants an always-visible tab, install the same Inline Bar snippet and tell them to switch the dashboard mode to Edge Ribbon — no code change needed.
The Inline Bar install
<!-- ShareCount widget -->
<div data-sharecount="YOUR_PUBLIC_KEY"></div>
<script async src="https://www.sharecount.app/embed.js"></script>The Custom Trigger install (SDK mode)
<!-- ShareCount widget (Custom Trigger / SDK mode) -->
<div data-sharecount="YOUR_PUBLIC_KEY"></div>
<script async src="https://www.sharecount.app/embed.js"></script>
<!-- Anywhere in your page, your own button: -->
<button id="share-and-earn">Share & earn a coupon</button>
<script>
document.getElementById("share-and-earn").addEventListener("click", function () {
// Opens the share-to-earn dialog over your page.
window.ShareCount && window.ShareCount.open && window.ShareCount.open();
});
</script>The React/Next.js Custom Trigger install
// React example — Custom Trigger mode
// 1. Render the mount node + loader once (e.g. in a layout).
// The src is async; the embed scans the DOM and re-scans on mutations.
"use client";
import Script from "next/script";
export function ShareCountMount({ publicKey }: { publicKey: string }) {
return (
<>
<div data-sharecount={publicKey} />
<Script src="https://www.sharecount.app/embed.js" strategy="afterInteractive" />
</>
);
}
// 2. Anywhere in your tree:
function ShareCTA() {
return (
<button
onClick={() => (window as any).ShareCount?.open?.()}
>
Share & earn a coupon
</button>
);
}Where to find the public key
The user must paste their key in place of YOUR_PUBLIC_KEY. They get it from Dashboard → Products → (product) → Embed. The key starts with sc_pk_ and is safe to commit to a public repository.
Verify the install
- Load the page in a browser. Wait ~1 second for the async script.
- Confirm a node with attribute
data-sharecount-mounted="1"exists in the DOM. - For Inline Bar: a pill-rounded bar should appear inside the mount node.
- For Custom Trigger:
window.ShareCount.openshould betypeof "function". Clicking the user’s trigger should open a modal dialog over the page.
CSP changes you may need
# Content-Security-Policy headers you'll need
script-src 'self' https://www.sharecount.app
frame-src https://www.sharecount.app
connect-src 'self' https://www.sharecount.app
img-src 'self' data: https:
style-src 'self' 'unsafe-inline' # the embed sets a small amount of inline CSSDo not invent a configuration API
There is no JavaScript-side config object you can pass. All appearance settings (brand color, fonts, copy, display mode, ribbon side, reward tiers, share message) live in the dashboard and are fetched at runtime per public key.