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 browser tracking restrictions 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 ──>│ Signal endpoint │──batch──>│ GA4 API │
│ (5.2 KB) │ first-party │ │ │ Meta API │
│ │ │ process + │ │ TikTok │
│ datafly.page()│ │ deliver │ │ Pinterest│
│ datafly.track()│ │ │ │ Snapchat │
│ datafly.identify│ └──────────────────┘ └──────────┘
└──────────────┘- Datafly.js loads from your own subdomain (e.g.,
collect.example.com/js/<pipeline_key>/df_example.js) as a first-party script - It sends page views automatically (on load and on single-page-app route changes) and captures the custom events and user identity your code sends
- Events are sent to your Datafly Signal collection endpoint
- Events are processed through your configured pipelines
- Signal delivers 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 | 5.2 KB gzipped | 1 per event | First-party |
Datafly.js is modular — only the modules you’ve configured ship in your build. Bundles sit around 5.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; all cookies are first-party so they aren’t affected by browser tracking restrictions
- Vendor ID generation — generates vendor-compatible IDs (GA4
client_id, Metafbp/fbc, TikTok, Pinterest, Snapchat) 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
- Resilient transport — each event is sent as soon as it happens, kept in
localStorageuntil acknowledged and retried with backoff; anything unsent is flushed withnavigator.sendBeaconwhen the page is hidden - Zero runtime errors — all operations are wrapped in try/catch; analytics never breaks your site
API overview
The script tag initialises the collector and sends page views for you, so these are the calls your own code makes:
// Page views are automatic. Call page() only when Page tracking is set to None
datafly.page()
// Track a custom event
datafly.track('Order Completed', { orderId: '12345', revenue: 99.99 })
// Identify a user
datafly.identify('user-123', { email: 'jane@example.com' })
// Associate with a company
datafly.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