JavaScript / Web SDK

Browser SDK for event tracking, identity, web push (FCM), and in-app messages. This page covers CDN / plain HTML and the core API. Use the sidebar for React or Vue / Angular. Version 1.2.0.

Overview

The Growise Web SDK is a singleton: window.growise (UMD) or the default ES export. After init it registers the device, receives a server-issued guest_id, batches events, and can load remote push settings.

  • Event tracking and analytics (batched, offline-safe queue until guest_id)
  • User identity and profile management (identify / onUserLogin / profilePush)
  • Web push via Firebase FCM
  • In-app messages: modal, banner, slide-in

Using a framework?

Same package (@growise/web-sdk). Framework setup is on separate pages:

  • React / Next.js → React in the sidebar
  • Vue 3 / Angular → Vue / Angular in the sidebar

Bundles

  • growise.umd.js — script tag / CDN (vanilla HTML)
  • growise.es.js — ES module import with a bundler

Get your API key

  • Open the Growise dashboard
  • Go to Settings → Project / API Keys
  • Copy your project API key (format: gk_...)

Plain HTML (CDN)

Script taghtml
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>My Site</title>
  <script src="https://cdn.thegrowise.com/js/v1/growise.umd.js"></script>
  <script>
    window.growise.init('YOUR_PROJECT_API_KEY', { env: 'prod' });
  </script>
</head>
<body>
  <button onclick="growise.track('CTA Clicked', { source: 'hero' })">
    Track click
  </button>
</body>
</html>

npm / bundler

Call init() once on app startup, before other SDK methods.

Installbash
npm install @growise/web-sdk
Initializejavascript
import growise from '@growise/web-sdk'

await growise.init('YOUR_PROJECT_API_KEY', {
  env: 'prod',
  appVersion: '1.0.0',
})

growise.track('Page Ready')

Environments

Defaults: hostname localhost → local; otherwise prod. Sandbox hosts and URLs come from your Growise project settings — do not hardcode internal endpoints in public apps.

  • local — local development
  • dev / stag — sandbox (from project settings)
  • prod — production
Init with envjavascript
growise.init(globalThis._importMeta_.env.VITE_GROWISE_API_KEY, {
  env: 'prod',
  appVersion: '2.4.1',
})

API — init(apiKey, options?)

Must be called once before other methods. On success: device_id, guest_id, auto-tracking, optional push settings.

  • env — local | dev | stag | prod (auto by default)
  • gateway — SDK settings / push config base URL
  • eventsBase — device, identify, logout, track base URL
  • endpoint — optional custom track URL
  • appVersion — sent as $app_version on events

API — track(eventName, properties?)

Batched (up to 100 or every 5s) via sendBeacon (fetch fallback). Queued until guest_id exists.

Track eventjavascript
growise.track('Product Viewed', {
  product_id: 'SKU-12345',
  category: 'Footwear',
  price: 2499,
})

API — onUserLogin / identify

onUserLoginjavascript
growise.onUserLogin({
  Site: {
    Identity: 'usr_99812',
    Name: 'Sarah Connor',
    Email: 'sarah@example.com',
    Phone: '+15550199',
  },
  Subscription: 'Enterprise',
})
identifyjavascript
await growise.identify('usr_99812', {
  name: 'Sarah Connor',
  email: 'sarah@example.com',
})

API — profilePush / profileIncrement

profilePushjavascript
growise.profilePush({
  Theme_Preference: 'Dark',
  Last_Purchase_Category: 'Books',
})
profileIncrementjavascript
growise.profileIncrement('loyalty_points', 100)
growise.profileIncrement('referrals')

API — logout()

Logoutjavascript
await growise.logout()

Privacy, push & in-app

Opt-outjavascript
growise.setOptOut(true)
growise.setOptOut(false)
Notificationsjavascript
growise.askNotificationPermission()
In-appjavascript
growise.showInAppNotification({
  id: 'promo_banner_01',
  type: 'modal',
  title: 'Flash Sale',
  body: 'Get 30% off for the next 2 hours.',
  primary_action: { text: 'Shop Now', url: '/store' },
})

Identity model

  • device_id — permanent; survives logout
  • guest_id — server-issued; rotates on logout
  • user_id — set after identify; cleared on logout
Debugjavascript
growise.identity.getDeviceId()
growise.identity.getGuestId()
growise.identity.getUserId()

Automatic tracking

  • $init, app_installed, app_opened, $pageview, app_closed
  • Sessions expire after 30 minutes of inactivity

Web push setup

  • Enable push in the dashboard
  • Host firebase-messaging-sw.js at site root
  • SDK loads Firebase config from /api/sdk/settings
  • Call askNotificationPermission() when needed

Best practices

  • Call init() once
  • Identify after login; logout() on sign-out
  • Past-tense event names; env vars for API keys
  • Wire setOptOut to consent

Troubleshooting

  • No events — check /device/register and /track
  • Tracks deferred — wait for guest_id
  • Opt-out stuck — clear _gw_optout

Integration checklist

  • API key · SDK loaded · init on start
  • identify after auth · track key events · logout on sign-out
  • Optional push SW · verify in debugger