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 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│              └──────────────────┘          └──────────┘
└──────────────┘
  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 Signal collection endpoint
  4. Events are processed through your configured pipelines
  5. Signal delivers 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.js5.2 KB gzipped1 per batchFirst-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:

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; all cookies are first-party so they aren’t affected by browser tracking restrictions
  • Vendor ID generation — generates vendor-compatible IDs (GA4 client_id, Meta fbp/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
  • 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
datafly.init({ pipelineKey: 'dk_...', endpoint: 'https://data.example.com' })
 
// Track a page view
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