Skip to main content
Back to Guides & Use Cases

Ecommerce 2.0 Multi-Currency Data Extraction

Extract user, product & multi-currency pricing data via GraphQL

This guide shows how to extract user, product, and pricing data from Thought Industries when using Ecommerce 2.0 with multi-currency support. Use this for integrating with external ecommerce systems or business intelligence tools.

Prerequisites

  • Ecommerce 2.0 (Foxy) must be enabled
  • Multi-currency pricing configured
  • GraphQL API access

1. User & Company Data

Access user information immediately from window.CONF.preload. Includes email, name, ID, and the user's preferred currency.

var currentUser = window.CONF.preload.currentUser.currentUser;
var company = window.CONF.preload.company;

console.log('User Email:', currentUser.email);
console.log('Preferred Currency:', currentUser.preferredCurrency);
console.log('Company Subdomain:', company.subdomain);

2. Product & Multi-Currency Pricing (GraphQL)

To get product information with all currency pricing options, use the GraphQL API.

// Endpoint: https://[your-domain]/graphql
// Operation: CourseGroupBySlugQuery
// Variable: {"slug": "course-slug"}

// Available Product Fields:
//   course.id, course.title, course.slug, course.sku

// Available Pricing Fields (prices array):
//   currencyCode   — e.g. "EUR", "USD", "GBP"
//   unitAmount     — price in cents (40000 = 400.00)
//   isDefault      — boolean, indicates default currency
//   instructorAccessUnitAmount
//   suggestedRetailUnitAmount
//   locale         — e.g. "en_US", "fr_FR"

Step-by-Step Implementation

Step 1 — Get User's Preferred Currency

Read the user's selected currency from window.CONF.preload.

var currentUser = window.CONF.preload.currentUser.currentUser;
var userCurrency = currentUser.preferredCurrency;
console.log('User viewing prices in:', userCurrency);

Step 2 — Fetch Course with All Pricing

function getCourseData(courseSlug) {
  var domain = 'https://' + window.CONF.preload.company.subdomainWithHost;
  return fetch(domain + "/graphql", {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      "operationName": "CourseGroupBySlugQuery",
      "variables": { "slug": courseSlug }
    })
  })
  .then(res => res.json())
  .then(({ data }) => {
    return data.CourseGroupBySlug.courses.find(c => c.slug === courseSlug);
  });
}

Step 3 — Match Price to User's Currency

function getPriceForUser(course, userCurrency) {
  // Try user's preferred currency first
  var price = course.prices.find(p => p.currencyCode === userCurrency);

  // Fall back to default currency
  if (!price) {
    price = course.prices.find(p => p.isDefault === true);
  }
  return price;
}

Step 4 — Extract Data for External Systems

function extractEcommerceData(course, price, currentUser) {
  return {
    customer: {
      email: currentUser.email,
      firstName: currentUser.firstName,
      lastName: currentUser.lastName,
      id: currentUser.id,
      preferredCurrency: currentUser.preferredCurrency
    },
    product: {
      id: course.id,
      title: course.title,
      slug: course.slug,
      sku: course.sku
    },
    pricing: {
      currencyCode: price.currencyCode,
      unitAmount: price.unitAmount,
      amountInDollars: price.unitAmount / 100,
      formattedAmount: (price.unitAmount / 100).toFixed(2),
      isDefault: price.isDefault
    }
  };
}

Complete Working Example

Copy-paste-ready script for Header or Footer Scripts. Runs on course pages, fetches pricing via GraphQL, and builds a structured data object.

<script>
(function() {

  // Only run on course pages
  if (!window.location.pathname.includes("/courses/")) return;

  var currentUser = window.CONF.preload.currentUser.currentUser;
  var company = window.CONF.preload.company;
  var courseSlug = window.location.pathname.replace('/courses/', '');
  var domain = 'https://' + company.subdomainWithHost;

  fetch(domain + "/graphql", {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      "operationName": "CourseGroupBySlugQuery",
      "variables": { "slug": courseSlug }
    })
  })
  .then(res => res.json())
  .then(({ data }) => {
    var course = data.CourseGroupBySlug.courses.find(c => c.slug === courseSlug);
    var userCurrency = currentUser.preferredCurrency;
    var price = course.prices.find(p => p.currencyCode === userCurrency)
             || course.prices.find(p => p.isDefault === true);

    var ecommerceData = {
      customer: {
        email: currentUser.email,
        firstName: currentUser.firstName,
        lastName: currentUser.lastName,
        id: currentUser.id
      },
      product: {
        id: course.id,
        title: course.title,
        slug: course.slug,
        sku: course.sku
      },
      pricing: {
        currencyCode: price.currencyCode,
        unitAmount: price.unitAmount,
        amountFormatted: (price.unitAmount / 100).toFixed(2)
      }
    };

    console.log('Ecommerce Data:', ecommerceData);
    // sendToExternalSystem(ecommerceData);
  })
  .catch(err => console.error('Error fetching course data:', err));

})();
</script>

Template Substitutions Don't Work for Multi-Currency

The {{priceInCents}} and {{priceInDollars}} template substitutions in tracking scripts show the default currency only, NOT the user's selected currency. You must use GraphQL to get accurate multi-currency pricing.

Common Use Cases

Send to External Ecommerce Platform

// Send to Shopify, WooCommerce, etc.
fetch('https://your-ecommerce-api.com/add-to-cart', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify(ecommerceData)
})
.then(res => res.json())
.then(data => console.log('Success:', data))
.catch(err => console.error('Error:', err));

Track with Google Analytics (GA4)

// Send to GA4 with correct currency
if (window.gtag) {
  gtag('event', 'view_item', {
    currency: ecommerceData.pricing.currencyCode,
    value: ecommerceData.pricing.unitAmount / 100,
    items: [{
      item_id: ecommerceData.product.id,
      item_name: ecommerceData.product.title,
      price: ecommerceData.pricing.unitAmount / 100
    }]
  });
}

Display Currency on Page

var priceElement = document.querySelector('.enroll__price');
if (priceElement) {
  priceElement.setAttribute('title', ecommerceData.pricing.currencyCode);
  priceElement.textContent = ecommerceData.pricing.currencyCode + ' ' +
                            ecommerceData.pricing.amountFormatted;
}

Data Reference

Data PointSourceExampleNotes
User Emailwindow.CONF.preload[email protected]Always available
User IDwindow.CONF.preload833699ce-2ef2-…UUID format
Preferred Currencywindow.CONF.preloadEUR, USD, GBPUser's selected currency
Course IDGraphQL2af94506-10ca-…UUID format
Course TitleGraphQLIntro to JavaScriptFull course name
Course SKUGraphQLJS-101May be empty
Currency CodeGraphQLEURISO 4217 code
Unit AmountGraphQL40000Amount in cents (400.00)
Is DefaultGraphQLtrue / falseIndicates default currency

Important Notes

Must Use GraphQL

To get accurate multi-currency pricing, you MUST fetch via GraphQL — it's the only reliable source.

Amount Format

All amounts are in cents (e.g., 40000 = 400.00). Divide by 100 to get decimal format.

Fallback to Default

If user's preferred currency isn't found in the prices array, use the price where isDefault === true.

Prices Array

Each course has a prices[] array with pricing for all configured currencies. Match by currencyCode.

Where to Add These Scripts

LocationPathScope
Header ScriptsSettings → Layout Settings → Header ScriptsAll pages
Footer ScriptsSettings → Layout Settings → Footer ScriptsAll pages
Add Cart ScriptsSettings → Layout Settings → Tracking → Add Cart Item ScriptsCart events
Checkout ScriptsSettings → Layout Settings → Tracking → Checkout Scripts – Step 1Checkout

For multi-currency data extraction, use Header or Footer Scripts since you need access to the full page context.

Troubleshooting

ProblemSolution
Getting USD when user views EURDon't use template substitutions. Use the GraphQL method described above.
preferredCurrency is undefinedUser hasn't selected a currency. Fall back to price where isDefault === true.
prices array is emptyMulti-currency pricing may not be configured for this course. Check course settings.
GraphQL query returns errorVerify the operation name is exactly "CourseGroupBySlugQuery" and the slug is correct.

Related