Copy-ready examples for the released GetFluxly SDK.
Use these snippets with @getfluxly/sdk-js. Browser snippets use GFLUX_API_KEY and window.__GFLUX__. Server snippets use Bearer gf_live_REPLACE_ME. Keep https://api.getfluxly.com as the API host.
Production note
Do not block a user-facing request on analytics. Send GetFluxly events from the browser SDK, a background job, or a fire-and-forget server call with error handling.
Install
Install the browser SDK
Pick script tag for regular websites or npm for bundled frontend apps.
Script tag for any website
Use this for Django, Rails, PHP, static HTML, or any site where you can paste scripts.
<script>
window.__GFLUX__ = {
apiKey: "GFLUX_API_KEY",
apiHost: "https://api.getfluxly.com"
};
</script>
<script src="https://cdn.jsdelivr.net/npm/@getfluxly/sdk-js@latest/dist/gflux.iife.js"></script>Install from npm
Use the package in React, Next.js, Vue, Svelte, and other bundled apps.
npm install @getfluxly/sdk-jsBasic npm usage
Set the API key before the SDK loads so auto-capture starts with the right project.
window.__GFLUX__ = {
apiKey: "GFLUX_API_KEY",
apiHost: "https://api.getfluxly.com"
};
import "@getfluxly/sdk-js";Frameworks
Framework examples
Use these when your app has a framework lifecycle that controls when browser code runs.
React usage
Load the SDK once when your app mounts.
import { useEffect } from "react";
import "@getfluxly/sdk-js";
export function App() {
useEffect(() => {
window.__GFLUX__ = {
apiKey: "GFLUX_API_KEY",
apiHost: "https://api.getfluxly.com"
};
}, []);
return <YourApp />;
}Next.js usage
Use a client component so the browser-only SDK loads after hydration.
"use client";
import { useEffect } from "react";
export function GetFluxly() {
useEffect(() => {
window.__GFLUX__ = {
apiKey: "GFLUX_API_KEY",
apiHost: "https://api.getfluxly.com"
};
import("@getfluxly/sdk-js");
}, []);
return null;
}Vue usage
Set the browser config first, then import the SDK in your app entry.
window.__GFLUX__ = {
apiKey: "GFLUX_API_KEY",
apiHost: "https://api.getfluxly.com"
};
import("@getfluxly/sdk-js");Svelte usage
Use onMount so the SDK only loads in the browser.
<script>
import { onMount } from "svelte";
onMount(() => {
window.__GFLUX__ = {
apiKey: "GFLUX_API_KEY",
apiHost: "https://api.getfluxly.com"
};
import("@getfluxly/sdk-js");
});
</script>Browser API
Identify users and track product events
Auto-capture handles the basics. These calls add user identity and business events.
Identify a logged-in user
Call this after login or signup to connect anonymous activity to a known user.
window.gflux?.identify("user_123", {
email: "jane@example.com",
name: "Jane Doe",
plan: "pro"
});Track a custom event
Use custom events for business actions like purchases, upgrades, and key workflow steps.
window.gflux?.track("purchase_completed", {
order_id: "ord_456",
total_usd: 99.99,
currency: "USD"
});Reset on logout
Clear the user identity when someone logs out or switches accounts.
window.gflux?.reset();Destroy the SDK
Flush queued events and remove browser listeners when you need to tear down the SDK.
window.gflux?.destroy();Server API
Send backend events
Use the HTTP events API for webhooks, billing events, and server-side workflows.
Node.js server usage
Send server events without blocking the user-facing request.
function trackGetFluxlyEvent(payload) {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 1500);
fetch("https://api.getfluxly.com/v1/events", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer gf_live_REPLACE_ME"
},
body: JSON.stringify(payload),
signal: controller.signal
})
.catch((error) => {
console.error("GetFluxly event failed", error);
})
.finally(() => {
clearTimeout(timeout);
});
}
trackGetFluxlyEvent({
event: "invoice_paid",
external_id: "user_123",
properties: {
invoice_id: "inv_456",
total_usd: 99.99
}
});Express server usage
Respond first after your own app work succeeds, then send analytics in the background.
app.post("/webhooks/stripe", async (req, res) => {
// Save billing state in your own database before sending analytics.
// await saveSubscription(req.body);
res.sendStatus(204);
fetch("https://api.getfluxly.com/v1/events", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer gf_live_REPLACE_ME"
},
body: JSON.stringify({
event: "subscription_started",
external_id: req.body.customer_id,
properties: {
plan: req.body.plan,
subscription_id: req.body.subscription_id
}
})
}).catch((error) => {
console.error("GetFluxly event failed", error);
});
});Python server usage
Use a timeout so your app does not hang if the network is slow.
import requests
requests.post(
"https://api.getfluxly.com/v1/events",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer gf_live_REPLACE_ME",
},
json={
"event": "invoice_paid",
"external_id": "user_123",
"properties": {
"invoice_id": "inv_456",
"total_usd": 99.99,
},
},
timeout=5,
)Go server usage
Post JSON to the events endpoint with your project API key.
payload := strings.NewReader(`{
"event": "invoice_paid",
"external_id": "user_123",
"properties": {
"invoice_id": "inv_456",
"total_usd": 99.99
}
}`)
req, _ := http.NewRequest("POST", "https://api.getfluxly.com/v1/events", payload)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer gf_live_REPLACE_ME")
_, _ = http.DefaultClient.Do(req)PHP server usage
Use cURL from PHP apps to post backend events.
$payload = json_encode([
"event" => "invoice_paid",
"external_id" => "user_123",
"properties" => [
"invoice_id" => "inv_456",
"total_usd" => 99.99,
],
]);
$ch = curl_init("https://api.getfluxly.com/v1/events");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Authorization: Bearer gf_live_REPLACE_ME",
],
CURLOPT_POSTFIELDS => $payload,
CURLOPT_RETURNTRANSFER => true,
]);
curl_exec($ch);
curl_close($ch);cURL usage
Use this to test the server events endpoint from a terminal.
curl -X POST https://api.getfluxly.com/v1/events \
-H "Content-Type: application/json" \
-H "Authorization: Bearer gf_live_REPLACE_ME" \
-d '{
"event": "invoice_paid",
"external_id": "user_123",
"properties": {
"invoice_id": "inv_456",
"total_usd": 99.99
}
}'Autocapture
Control auto-capture
Keep the defaults on, or disable specific event types when a product needs tighter control.
Turn auto-capture options on or off
The SDK auto-captures pageviews, clicks, form submits, and page leave by default.
<script>
window.__GFLUX__ = {
apiKey: "GFLUX_API_KEY",
apiHost: "https://api.getfluxly.com",
autocapture: {
pageviews: true,
clicks: true,
forms: false,
pageLeave: false
}
};
</script>