Skip to content
  • There are no suggestions because the search field is empty.

How to Use Environment-Specific Global JavaScript in Convert

🔧 Add and Manage JavaScript for Each Environment in Convert Projects

IN THIS ARTICLE YOU WILL:

Convert now supports defining different Global JavaScript (JS) for individual project environments like "Production" or "Staging", alongside the existing “All Environments” setting. This update gives teams more control and flexibility to run environment-specific logic during testing or deployment.

📌 What Has Changed?

Previously, all environments within a project shared the same Global JavaScript. With this new feature:

  • You can define and save separate JavaScript for each environment (e.g., Production, Staging).

  • JavaScript under “All Environments” still applies globally.

  • Environment-specific JS does not overwrite, but runs after the “All Environments” code, giving it effective priority.

🔧 How to Use It

1. Access the Global JavaScript Section

Navigate to your Project in Convert and go to:

Configuration > Global Javascript

gp1

2. Choose Your Environment

Use the “Select Environment” dropdown to choose where to apply your code:

  • All Environments

  • Production

  • Staging
    (More environments may be listed depending on your project setup.)

gp2

3. Add JavaScript Per Environment

Each environment has its own code editor. Code added here will only execute in the chosen environment context.

gp3

gp4

gp5

💡 Tip: You can use environment-specific variables or logging to debug different environments:

(function(){
  const environment = "staging";

  if (environment === "staging") {
    console.log("Running Staging Environment JS");
  } else if (environment === "production") {
    console.log("Running Production Environment JS");
  } else {
    console.log("Running JS for All Environments");
  }
})();

4. Compare JS Code Across Environments

Toggle “Compare JS Code” to view your environment-specific scripts in tab view.

gp7

This is helpful for spotting differences across staging, production, and shared JS.

5. Save Changes

Click Save Changes after editing any environment’s JavaScript.

The button label has been updated from "Save Global Javascript" to "Save Changes" to reflect multi-environment support.

🔍 Execution Order

  1. JS under “All Environments” is always executed first.

  2. If there’s environment-specific JS (e.g., Staging or Production), it executes after the global JS.

    This means environment-specific code can rely on or override logic defined in the global section without duplicating common functionality.

📘 Info Tooltip

You’ll see an info icon next to “Select Environment.” Hovering it displays:

“Select an environment to view or edit its JavaScript. Code saved under ‘All Environments’ applies globally, unless a specific environment has its own custom script.”

gp5

✅ Summary

This feature is ideal for teams that:

  • Run experiments differently in Production vs. Staging

  • Want to isolate testing logic from live user logic

  • Avoid duplicated JS code across environments

📣 Notes

  • If no environment-specific code is defined, only the “All Environments” JS will execute.

  • This update is now live on the Convert backend and REST API, with no impact on legacy projects or scripts.

Start using this feature to better organize your experimentation logic!


🟢 Still need help? Visit support.convert.com