Datafly.js SDKOverview

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│               └──────────────────┘          └──────────┘
└──────────────┘
  1. Datafly.js loads from your own subdomain (e.g., data.example.com/d.js) as a first-party script
  2. It captures page views, custom events, and user identity
  3. Events are batched and sent to your Ingestion Gateway endpoint
  4. The server processes events through your configured pipelines
  5. Delivery Workers send data server-to-server to each vendor’s API

Size comparison

ApproachTotal JS loadedNetwork requestsCookie access
Traditional tags (GA4 + Meta + TikTok + Pinterest + Snap)200—400 KB15—30+Third-party
Google Tag Manager + vendor tags150—300 KB10—25+Third-party
Datafly.js4.2 KB gzipped1 per batchFirst-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:

VendorWhat Datafly replacesServer-side delivery
Google Analytics 4gtag.js / analytics.jsGA4 Measurement Protocol
Meta (Facebook)fbevents.js (Meta Pixel)Conversions API
TikTokanalytics.js (TikTok Pixel)Events API
Pinterestpintrk.js (Pinterest Tag)Conversions API
Snapchatscevent.min.js (Snap Pixel)Conversions API
LinkedInLinkedIn Insight TagConversions API
Google Adsgtag.js (conversion tracking)Google Ads API

Key features

  • First-party data collection — loads from your own subdomain, sets cookies via server Set-Cookie header (ITP-exempt)
  • Vendor ID generation — self-generates vendor-compatible IDs (GA4 client_id, Meta fbp/fbc, TikTok ttp, 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.sendBeacon with 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