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., collect.example.com/js/<pipeline_key>/df_example.js) as a first-party script
  2. 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
  3. Events are sent to your Datafly 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 eventFirst-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
  • Resilient transport — each event is sent as soon as it happens, kept in localStorage until acknowledged and retried with backoff; anything unsent is flushed with navigator.sendBeacon when 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