For coding agents
You have this guide and an App ID (app_...). Do these three things, in order:
- Load the SDK with one script tag carrying the App ID. Wait for
window.eykSdk. - Add sign-in: call
getSession()on page load; show a sign-in button that callssignIn()when the session isnull. - Run queries with
query()once a session exists. Discover member names withlistMetrics().
- Use the App ID exactly as given. Never invent, shorten, or hardcode a different one.
- Never call
signIn()automatically on page load. Only call it from a user action (a button click). - Never run
query()beforegetSession()returned a session. A signed-out query rejects withAUTH_REQUIRED; it does not redirect. - Never call the Eyk API directly. The SDK is the whole contract; there are no other endpoints to integrate.
- Never add a backend, proxy, API key, or secret for Eyk. The SDK runs in the browser and holds the user’s own session.
- Use member names from
listMetrics()or from this guide. Do not guess names.
Before you start
Someone with the Admin role in the Eyk organization must do this in Eyk under Agentic › Data apps. Agents cannot do it.- Register a data app. Each app gets a name and an App ID (
app_...). The App ID is public and safe to put in frontend code. - Add allowed origins. An origin is
scheme://host[:port]with no path. Sign-in only returns users to a registered origin.https://is required except forhttp://localhost:<port>, so add your local development origin too. - Invite the people who will use the app as members of the organization. Only approved members can sign in to a data app. What they see is governed by their access in Eyk, the same as in the Eyk dashboard.
Step 1: load the SDK
Add one script tag to the<head> of every page that uses Eyk. Replace the App ID with yours.
window.eykSdk and dispatches an eyksdk:ready event on window. Because the script is async, the event can fire before your code runs. Always check the global first:
Load from JavaScript instead of a script tag
Load from JavaScript instead of a script tag
Same result, useful in bundled apps where you do not control
index.html:eykSdk.init({ appId }) also exists for a script loaded without data-app-id. Calling init with a different App ID clears the current session.TypeScript types
TypeScript types
Type declarations are served next to the script at
https://edge.eykdata.com/sdk/v1/eyk-sdk.d.ts. Download the file into your project and import its types, or copy the SDK reference below. The file declares window.eykSdk and the eyksdk:ready event.Test environment
Test environment
An App ID belongs to one Eyk environment. Apps registered on the Eyk test platform load the SDK from
https://edge.eykdata.dev/sdk/v1/eyk-sdk.js instead. The Manual setup section of the app’s detail page in Eyk always shows the exact script tag for that app.Step 2: add sign-in
Sign-in is a full-page redirect to Eyk and back to your page. The SDK completes the exchange when the page reloads, insidegetSession().
getSession()resolvesnullwhen nobody is signed in. It never redirects.signIn()defaultsreturnToto the current URL. The origin ofreturnTomust be an allowed origin of the app, or Eyk shows an error page instead of a login.- After returning, the SDK removes the
codeandstateparameters from the URL. Your own query parameters survive the round trip. - A session survives page reloads for about 7 days without a new redirect. Then the next
getSession()returnsnulland the user signs in again. - Signing out in one tab signs out the other tabs of the same app.
- Sign-in needs a secure context:
https://, orhttp://localhost. Inside a cross-origin iframe the redirect flow cannot run.
React example
React example
The same flow as a hook.
sdk is available in both signed-out and signed-in states, so the sign-in button can call it.Step 3: run queries
Ask for measures and dimensions by name. Results come back already filtered to what the signed-in user may see.name.<granularity> (the start of the bucket). Both are ISO timestamps.
Number() before you add or format them.
Query shape
Discover member names
listMetrics() returns the catalog the signed-in user may query. Use it to find names and to build pickers; do not guess names.
Query rules
- Do not mix measures from different fact metrics in one query.
fact_sales_items.net_saleswithfact_attributions.channel_costis invalid. Run two queries and combine in your app. - Time dimension names are base names. Wrong:
{ dimension: "fact_sales_items.line_timestamp.month" }. Right:{ dimension: "fact_sales_items.line_timestamp", granularity: "month" }. The suffixed form only appears in result keys. fact_attributionsuses one attribution model per query. The default model is applied when you add no filter. To pick another, filter ondim_attribution_models.display_namewith one value, for example"Last Touch".- Members you cannot see read as unknown. A hidden or restricted member fails with
INVALID_QUERYand reasonunknown_member, never with a permission error. - Keep queries aggregated. Pull grouped rows for the period you display, not every order.
limitcaps at 10000 rows.
Errors
Every rejected promise fromgetSession(), signIn(), signOut(), query(), and listMetrics() is an EykError with name: "EykError", a code, a message, and optional details and HTTP status. Wrong use of the SDK itself (no App ID, wrong argument type) throws a TypeError synchronously instead.
Verification
Run through this list before you call the integration done.- Load: open the page.
window.eykSdk.versionis a string in the console. No SDK errors. - Signed out: the page shows a sign-in button and does not redirect on its own.
- Sign in: clicking the button goes to Eyk. After signing in, the browser returns to the page you started on, with clean URL parameters, and
getSession()returns{ user: { email, name } }. - Query: a query returns
{ rows }with the members you asked for. Numbers render correctly afterNumber(). - Sign out: after
signOut(),getSession()returnsnulland the sign-in button is back. - Local development: the same works on
http://localhost:<port>after that origin is added to the app’s allowed origins.
Common mistakes
SDK reference
data-app-id attribute, the method names, the query shape, and the error codes above are a frozen v1 contract. Breaking changes ship as /sdk/v2/; v1 embeds keep working.
🤝 Questions or stuck on a query? Reach the Eyk team through the in-product chat.
