Datafly.js SDK
Datafly.js is a lightweight JavaScript collector that replaces all third-party vendor tags on your website with a single first-party script. Instead of loading dozens of marketing and analytics tags directly in the browser, Datafly.js captures events client-side and sends them to your own server endpoint, where they are processed and delivered server-to-server to each vendor’s API.
Why Datafly.js?
Traditional tag management loads vendor JavaScript directly into the browser. Each vendor tag adds weight, creates additional network requests, and exposes your site to third-party code execution. This approach has compounding problems:
- Performance degradation — every vendor tag adds 10—100KB+ of JavaScript
- Data loss — ad blockers and ITP block third-party cookies and scripts
- Privacy risk — vendor scripts can access the full DOM and user data
- Reliability — vendor outages cause tag failures and broken tracking
Datafly.js solves all of these by replacing every vendor tag with one lightweight collector.
How it works
Browser Your Server Vendors
┌──────────────┐ ┌──────────────────┐ ┌──────────┐
│ Datafly.js │──── events ──>│ Ingestion Gateway │──batch──>│ GA4 API │
│ (4.2 KB) │ first-party │ │ │ Meta API │
│ │ │ Event Processor │ │ TikTok │
│ _df.page() │ │ Delivery Workers │ │ Pinterest│
│ _df.track() │ │ │ │ Snapchat │
│ _df.identify│ └──────────────────┘ └──────────┘
└──────────────┘- Datafly.js loads from your own subdomain (e.g.,
data.example.com/d.js) as a first-party script - It captures page views, custom events, and user identity
- Events are batched and sent to your Ingestion Gateway endpoint
- The server processes events through your configured pipelines
- Delivery Workers send data server-to-server to each vendor’s API
Size comparison
| Approach | Total JS loaded | Network requests | Cookie access |
|---|---|---|---|
| Traditional tags (GA4 + Meta + TikTok + Pinterest + Snap) | 200—400 KB | 15—30+ | Third-party |
| Google Tag Manager + vendor tags | 150—300 KB | 10—25+ | Third-party |
| Datafly.js | 4.2 KB gzipped | 1 per batch | First-party |
Datafly.js is under 8 KB gzipped in all configurations, including custom builds with vendor-specific modules. The base collector without optional vendor modules is 4.2 KB gzipped.
What it replaces
Datafly.js replaces the client-side JavaScript for all supported vendors. You remove all vendor script tags and load Datafly.js instead. The platform currently supports server-side delivery to:
| Vendor | What Datafly replaces | Server-side delivery |
|---|---|---|
| Google Analytics 4 | gtag.js / analytics.js | GA4 Measurement Protocol |
| Meta (Facebook) | fbevents.js (Meta Pixel) | Conversions API |
| TikTok | analytics.js (TikTok Pixel) | Events API |
pintrk.js (Pinterest Tag) | Conversions API | |
| Snapchat | scevent.min.js (Snap Pixel) | Conversions API |
| LinkedIn Insight Tag | Conversions API | |
| Google Ads | gtag.js (conversion tracking) | Google Ads API |
Key features
- First-party data collection — loads from your own subdomain, sets cookies via server
Set-Cookieheader (ITP-exempt) - Vendor ID generation — self-generates vendor-compatible IDs (GA4
client_id, Metafbp/fbc, TikTokttp, Pinterest_pin_unauth, Snapchat_scid) so vendor pixels are never needed - Click ID capture — automatically captures ad click IDs from URLs (
gclid,fbclid,ttclid,epik,ScCid,li_fat_id) - Consent management — built-in support for OneTrust, Cookiebot, and custom consent platforms
- Cross-domain identity — encrypted token relay through Identity Hub for consistent identity across domains
- Batched transport — events are batched (up to 10 per request) and sent via
navigator.sendBeaconwith XHR fallback - Zero runtime errors — all operations are wrapped in try/catch; analytics never breaks your site
API overview
// Initialize
_df.init({ pipelineKey: 'dk_...', endpoint: 'https://data.example.com' })
// Track a page view
_df.page()
// Track a custom event
_df.track('Order Completed', { orderId: '12345', revenue: 99.99 })
// Identify a user
_df.identify('user-123', { email: 'jane@example.com' })
// Associate with a company
_df.group('company-456', { name: 'Acme Corp', plan: 'enterprise' })Next steps
- Installation — add Datafly.js to your site
- Configuration — full reference for all init options
- Consent Management — integrate with your CMP