CustomerGlu Developer Documentation
  • 🔧Getting started
  • 🔧Quickstart Guide for React Web Apps
  • 📱Quickstart Guide for React Native Apps
  • 📱Quickstart Guide for Flutter Apps
  • Integrating with SDKs
    • Web SDK
    • Mobile SDKs
      • How to Test Integration?
    • Cordova SDK
    • Shopify
  • Integrating with APIs
    • Register User/Device
    • Load Campaigns
    • Binding Webview to Native App Functions
    • 🔍Using __GLU_NUDGE_CLICK for Widget Visibility
    • 🎯API-based Segmentation Quickstart Guide
  • 🔌Third-Party Integrations
    • Source
      • Sending Events directly from Server
      • Segment
      • Moengage
      • Amplitude
      • Clevertap
      • Webengage
    • Destination
      • Analytics Webhook
      • Customer.io
      • Talon.One
      • Segment
      • MoEngage
      • Amplitude
      • Clevertap
      • WebEngage
      • Google Sheets
    • Cohort
      • Mixpanel
  • Miscellaneous Topics
    • Direct Campaign/Wallet URLs
    • Configuring Webhooks
      • Rewards Webhook
      • Nudge Webhook
    • Notifications
      • FCM
      • APNs
      • CustomerGlu Notification
      • Testing Nudges
    • Referral Campaigns
      • Firebase
      • Branch
    • Handling Non Logged-in Users
    • Testing Campaigns with User Logs
    • Using the Editor
      • How to edit Buttons in Campaigns
    • How to Create and Manage Segments in CustomerGlu
  • SCHEMA REPOSITORY
    • Webhook Schema
      • Reward Webhook Schema
      • Nudge Webhook Schema
      • Raw Event Webhook Schema
    • Webview Callback Schema
      • Analytics Event Schema
    • Analytics schema V4
      • Page Events
      • Track Events (UI)
      • Track Events (SDK)
      • State-Change Events
      • System Events
    • 🗝️FAQ
      • API Key
      • How to find and add Screen Names for Entrypoints
  • Demo Apps
    • Demo Apps
Powered by GitBook
On this page
  • What is Segmentation?
  • Prerequisites
  • API Endpoints
  • Implementation Examples
  • Regional Endpoints
  • Error Handling
  • Best Practices
  • Need Help?

Was this helpful?

  1. Integrating with APIs

API-based Segmentation Quickstart Guide

This guide covers everything you need to know about programmatically managing user segments for your CustomerGlu campaigns.

What is Segmentation?

Segmentation lets you target specific campaigns to specific users. With our APIs, you can add users to campaigns, check their status, and remove them when needed - all programmatically.

Prerequisites

Before you start:

  • ✅ Get your API key from the CustomerGlu Dashboard

  • ✅ Note your Campaign IDs from the Campaigns section

  • ✅ Have your User IDs ready (same as Registration API)

API Endpoints

1. Add a User to a Campaign

Request:

POST https://api-us.customerglu.com/segment/:campaignId/user/add
Content-Type: application/json
X-API-KEY: your-api-key

{
    "userId": "user-123"
}

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "success": true,
    "message": "User added to campaign successfully"
}

Effect: User immediately starts seeing the campaign and can earn associated rewards.

2. Check User's Campaign Status

Request:

POST https://api-us.customerglu.com/segment/:campaignId/user/status
Content-Type: application/json
X-API-KEY: your-api-key

{
    "userId": "user-123"
}

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "success": true,
    "data": {
        "isPresent": true  // or false if not in segment
    }
}

3. Remove a User from a Campaign

Request:

DELETE https://api-us.customerglu.com/segment/:campaignId/user/delete
Content-Type: application/json
X-API-KEY: your-api-key

{
    "userId": "user-123"
}

Response:

httpCopyHTTP/1.1 200 OK
Content-Type: application/json

{
    "success": true,
    "message": "User removed from campaign successfully"
}

Effect: Campaign stops appearing for this user; they stop earning campaign rewards.

Implementation Examples

Personalized Onboarding

javascriptCopy// When a new user signs up
function onUserSignup(userId) {
  // Add to onboarding campaign
  fetch('https://api-us.customerglu.com/segment/onboarding-campaign-id/user/add', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-KEY': 'your-api-key'
    },
    body: JSON.stringify({ userId })
  });
  
  // After completion, move to next campaign
  function moveToNextStage() {
    // Remove from onboarding
    fetch('https://api-us.customerglu.com/segment/onboarding-campaign-id/user/delete', {
      method: 'DELETE',
      headers: {
        'Content-Type': 'application/json',
        'X-API-KEY': 'your-api-key'
      },
      body: JSON.stringify({ userId })
    });
    
    // Add to core features campaign
    fetch('https://api-us.customerglu.com/segment/core-features-id/user/add', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'X-API-KEY': 'your-api-key'
      },
      body: JSON.stringify({ userId })
    });
  }
}

A/B Testing

javascriptCopy// Split users between variant campaigns
function assignVariant(userId) {
  const variant = Math.random() > 0.5 ? 'a' : 'b';
  const campaignId = `variant-${variant}-campaign-id`;
  
  fetch(`https://api-us.customerglu.com/segment/${campaignId}/user/add`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-KEY': 'your-api-key'
    },
    body: JSON.stringify({ userId })
  });
  
  return variant; // Track which variant was assigned
}

Regional Endpoints

Select the appropriate base URL for your region:

  • 🇺🇸 US: https://api-us.customerglu.com

Error Handling

The API returns standard HTTP status codes. Here are common errors and solutions:

HTTP/1.1 401 Unauthorized
Content-Type: application/json

{
    "success": false,
    "error": "Invalid API key"
}

Solution: Verify your API key is correct and active.

HTTP/1.1 404 Not Found
Content-Type: application/json

{
    "success": false,
    "error": "Campaign not found"
}

Solution: Double-check the campaign ID exists and is active.

Best Practices

  1. Check Before Modifying: Use the status endpoint to avoid redundant operations

  2. Error Handling: Implement proper error handling with retries for production systems

  3. Webhooks Integration: Connect user events to segmentation API calls for real-time targeting

  4. Caching: Cache segment membership locally for frequently checked users

  5. Logging: Track API calls and responses for debugging and audit purposes

Need Help?

Run into issues? Check these common troubleshooting steps:

  1. Verify API key permissions in your CustomerGlu Dashboard

  2. Ensure campaign IDs are correct and campaigns are active

  3. Check that user IDs match those in your CustomerGlu account

  4. Confirm you're using the correct regional endpoint

For more assistance, contact our developer support team via Slack

PreviousUsing __GLU_NUDGE_CLICK for Widget VisibilityNextThird-Party Integrations

Last updated 2 months ago

Was this helpful?

UAE: https://api-me.customerglu.com

IN: https://api-in.customerglu.com

🎯
🇦🇪
🇮🇳