Skip to main content

Documentation Portal

Quick Guide: Adding and Initializing the Analytics SDK

This page explains how to add and initialize the Global-e Analytics SDK on your website. Use this guide if you are not already using the Global-e Client SDK in your integration.

Note

This guide is intended only for merchants who are not using the client-side SDK in their Global-e integration. Please note that this is not the standard Global-e integration method.

Overview

The Analytics SDK lets you track browsing activity for shoppers by sending analytics events to Global-e. The SDK must be loaded and initialized on every page where you want to capture events. After initialization, you must immediately send the BrowsingStart event.

Implementation Steps
To add and initialize the Analytics SDK
  1. Add the Analytics SDK script to the <head> section of your site. Use the /PROD/ path for production, and /QA-INT/ or /STG/ for testing or development.

  2. Immediately after the script, add the initialization code, replacing the placeholder values with your own:

    1. merchantId: your unique merchant identifier provided by Global-e.

    2. shopperCountryCode: the two-letter ISO 3166-1 Alpha-2 country code of the shopper, updated dynamically from your country selector.

    3. cdnUrl: the Global-e environment URL. For production use https://webservices.global-e.com/, and for development use connect.bglobale.com (QA-INT) or connect2.bglobale.com (STG).

  3. After initialization, immediately call sendBrowsingStartEvent(). This step is critical for tracking user activity and must be repeated on every page load.

Example Implementation
<!DOCTYPE html>
<html>
<head>
  <script src="https://globale-analytics-sdk.global-e.com/PROD/bundle.js"></script>

  <script>
    // This function initializes the Global-e Analytics SDK
    async function initializeGEAnalytics() {
      try {
        const sdk = new AnalyticsSDK();

        // Replace the placeholder values below
        const merchantId = 'YOUR_MERCHANT_ID';
        const shopperCountryCode = 'ZZ'; // ISO 3166-1 Alpha-2
        const cdnUrl = 'https://webservices.global-e.com/'; // Production URL

        await sdk.init(merchantId, shopperCountryCode, {
          cdn: cdnUrl,
          browser: window
        });

        // After initialization, send the BrowsingStart event
        await sdk.sendBrowsingStartEvent();

      } catch (error) {
        console.error('Analytics SDK Initialization Failed:', error);
      }
    }

    // Call the function
    initializeGEAnalytics();
  </script>
</head>
<body>
  ...
</body>
</html>