Skip to main content

Code debt cleanup

Over time, as experiments, segments, and goals accumulate, your testing environment can become cluttered, leading to inefficiencies and potential errors. Regularly reviewing and cleaning up outdated elements is essential to maintaining a streamlined, high-performing Kameleoon setup. This article outlines the key steps to identifying and removing obsolete experiments, segments, and code to reduce technical debt, improve accuracy, and ensure a smoother workflow for your optimization efforts.

Debt cleanup is a time investment that pays off. Taking the time to clean up technical debt—whether it's outdated experiments, unused segments, or unnecessary code—greatly improves performance in the long run.

Before implementing the actions listed below, ensure you save a performance benchmark of your website, so you can measure the improvements afterward.

  • 🧪 Use PageSpeed Insights (or any other performance analysis tool you’re comfortable with) to analyze your site (desktop and mobile). Once the report is generated, click Copy Link (top-right)—this will save the report with data from the exact day of analysis (See screenshot below).

  • 🧩 Use the Kameleoon Chrome Extension to check performance and the size of experiments segments, goals, custom data and custom scripts. See screenshot below.

Once you’ve completed the cleanup actions below, run both analyses above again and compare the results to see the impact of your optimizations.

1. Web experiments/personalizations

On the Experiments page:

Delete outdated draft experiments

Use the menu on the right to filter for draft experiments, then delete all experiments older than three months (use the key date filter), along with recent ones you no longer need. To do this:

  1. Right-click an experiment's three-dots menu and click "Select".
  2. Click "Select all experiments" above.
  3. Choose "Delete" from the right menu. Alternatively, you can Archive them.

Stop paused experiments

Filter for paused experiments, then stop all experiments older than three months and any recent experiments you’re certain won’t be relaunched. Since bulk selection isn’t available for stopping experiments, you must manually select them one by one and click Stop in the right menu.

Divert/stop online experiments

Filter for online experiments and divert 100% of traffic to the winning variation if the data is reliable. This diversion ensures all visitors benefit from the optimized version without being split across variations. You can divert traffic in the experiment traffic allocation settings. If the winning variation is the original, you can stop the experiment.

Transfer and clean up diverted experiments

Filter for diverted experiments, then request your IT team to integrate the winning variation’s code into the site’s source code. Once implemented, stop and archive the experiment, which has the benefits of:

  • Eliminating unnecessary experiment scripts and improving page load speed.
  • Ensuring all users experience the optimized version without experiment conditions, since tools like Kameleoon may be blocked by ad blockers, for example.
  • Reducing the risk of conflicts between old experiments and new optimizations.

Archive stopped experiments

Filter for stopped experiments, then archive all remaining stopped experiments. To do this:

  1. Right-click an experiment's three-dots menu.
  2. Click Select > Select all experiments.
  3. Click Archive in the right menu. Alternatively, you can delete them.
tip

For Personalizations, follow the same steps above. For Feature Flags, follow this guide.

2. Segments/triggers

On the Segments and triggers pages:

Delete outdated draft segments

Use the right menu to filter for segments attached to “0 campaign”, then delete all segments older than three months (use the “key date” filter), along with recent ones you no longer need. To do this:

  1. Right-click a segment's three-dots menu.
  2. Click Select > Select all experiments > Delete
note

When applying the filter, some segments may still appear linked to campaigns. These are archived campaigns, which you can identify by hovering over the i icon—archived experiment names will be grayed out (See screenshot below).

Optimize segments based on JS

Filter segments for those that are attached to "one or more campaign(s)." Then, follow the guidelines in this documentation to optimize all segments based on a "JS custom condition." To quickly identify these segments, visit your website and open the browser console. Then, run the following code:

const obtainSegmentsBasedOnJS = info =>
Kameleoon.Internals.runtime.targetingSegments.filter(
item => JSON.stringify(item.tree).match(info)
);
// All segments based on a JS condition include the keyword "return" or "setTargeting"
console.log(obtainSegmentsBasedOnJS('return'));
console.log(obtainSegmentsBasedOnJS('setTargeting'));

The code above will return the list of segments using a JS custom condition (See screenshot below).

note

The JS condition will be moved to Triggers as of Q3 2025.

Rename segments

Kameleoon runs all segments that have been created or modified in your account within the past 90 days, as long as their targeting conditions do not include “page URL” or “Custom JavaScript” — even if they are not linked to any experiment. This process is used for opportunity detection. If you want to exclude certain segments from this process, you can rename them using one of the following prefixes: [DEV], [TEST], or [QA].

3. Goals

On the Goals page:

Disable unconverted goals

Use the menu on the right to filter for goals linked to “1 or more campaign(s)”. Then, disable any goal that hasn't recorded a conversion in the last 24 hours, if you think it's no longer relevant. To check the conversion count, hover over the i icon for each goal—a pop-in will show the number of conversions in the last 24 hours (see screenshot below).

Delete unused goals

Filter for goals attached to “0 campaign”, then delete any you no longer need. Even if not linked to a campaign, active goals still run online—so removing unused goals helps improve performance. To do this:

  1. Right-click a goal's three-dots menu.
  2. Click Select > Select all experiments.
  3. Click Delete in the right menu. Alternatively, you can Disable them.

Delete inactive goals

Filter for “inactive” goals, then delete all those you no longer need.

4. Custom data

All custom data runs online—so removing unused custom data helps improve performance.

On the Custom data page:

Delete unused custom data

Delete all custom data you no longer need.

Optimize custom data based on JavaScript

If a custom data is defined using custom JavaScript code, ensure the code does not run in an infinite loop. You can follow this guide to avoid performance issues.

To identify which custom data use JavaScript, visit your website, open the browser console, and run the following code:

Object.values(Kameleoon.Internals.runtime.Gatherer.configuration.customData)
.filter(custom_data => custom_data.method === "CUSTOM_CODE");

The code will return the list of custom data using JavaScript (See screenshot below).

5. Global script

Once you've completed all the steps above, navigate to: Admin ⇒ Projects ⇒ Configuration ⇒ General ⇒ Global custom script, then remove any code in the script that references the deleted segments, goals, or custom data.

To optimize your Global Script further, follow the guidelines outlined here. These tips will help ensure your code runs efficiently, remains maintainable, and performs well across all experiments.

tip

To make refactoring the Global Script easier and safer, you can split it into two versions using a cookie condition. This cookie condition lets you test the new script live in your browser while keeping the original script active for all other visitors.

Just add a custom cookie, like newKamGS=true, in your browser, then use the following code to conditionally load the Global Script:

if (document.cookie.includes('newKamGS=true')) {
// new Global Script (for your own QA/testing)
}
else {
// old Global Script (for all users)
}