@didtheyclick/sdk
v0.0.3
Published
Official JavaScript SDK for didthey.click — privacy-friendly web analytics. Browser tracking (init/track/identify) and server-to-server event tracking.
Maintainers
Readme
@didtheyclick/sdk
Official JavaScript SDK for didthey.click — privacy-friendly web analytics.
Install
npm install @didtheyclick/sdkQuickstart: script tag
The fastest way to start tracking pageviews — no build step required. Drop this before
</body> on every page:
<script
async
src="https://www.didthey.click/sdk/tracker.js"
data-website-id="YOUR_WEBSITE_ID"
></script>Once loaded, the tracker is available on window.__dtc:
<script>
window.__dtc.track('signup_completed', { plan: 'pro' });
window.__dtc.identify('user_123', { email: '[email protected]' });
</script>Optional attributes:
| Attribute | Description |
| -------------------- | ------------------------------------------------ |
| data-endpoint | Override the collection endpoint |
| data-debug | "true" to log tracker activity to the console |
| data-auto-pageview | "false" to disable automatic pageview tracking |
Browser usage (npm)
If you're bundling your own app, use createTracker directly instead of the script tag:
import { createTracker } from '@didtheyclick/sdk';
const tracker = createTracker({
websiteId: 'YOUR_WEBSITE_ID',
// endpoint: 'https://www.didthey.click/api/collect', // default
debug: false,
autoPageview: true
});
tracker.track('signup_completed', { plan: 'pro' });
tracker.identify('user_123', { email: '[email protected]' });
tracker.page(); // manually record a pageview (e.g. on SPA route change)Type-safe events
Augment the global DtcEventMap interface to get autocomplete and type-checked properties for
track():
declare global {
interface DtcEventMap {
signup_completed: { plan: string };
}
}Server usage
For server-to-server tracking (e.g. from a backend job, webhook handler, or any environment
without a browser), use the /server entry with a secret key (sk_...). Never expose the
secret key to the browser.
import { createServerTracker } from '@didtheyclick/sdk/server';
const tracker = createServerTracker({
secretKey: process.env.DTC_SECRET_KEY!, // sk_...
endpoint: 'https://www.didthey.click',
projectId: 'YOUR_PROJECT_ID'
});
tracker.track('subscription_renewed', {
userId: 'user_123',
properties: { plan: 'pro' }
});License
MIT
