Skip to main content

Use metric analysis

We will guide you to use the metric analysis function of the FeatureProbe platform. By writing back-end/front-end programs, use the SDK to realize the data reporting of custom events, and view the analysis results on the platform.

Create a toggle on the platform

  1. Log in to the FeatureProbe demo platform. If you log in for the first time, please enter your email address. You can continue to use your email to access your data in the future.
  2. Click +Toggle to create a new toggle. add
  3. Set the name and key to custom_event, click Create and publish. create
  4. Click custom_event from the toggle list to open the targeting details page. list
  5. Set the status to enabled. Change the return variation of the default rule to a percentage rollout. Set 50% to variation1, 50% to variation2. list
  6. Click the Publish button below and Confirm the changes. list

Save metrics and start iteration

  1. Open the Analysis Tab, Add a metric named Button Click Conversion, select the metric type as Conversion then select Custom event type, configure the event name as test_event, and click Save. list

  2. After the metric is saved successfully, click the Start iteration button to start collecting data. list

Control the backend program

We provide a backend code example, from which you can start to experience how the backend code report custom event.

Write code

  1. According to the language you are familiar with, download and open the corresponding back-end sample code.
git clone https://github.com/FeatureProbe/server-sdk-java.git
cd server-sdk-java

Open src/main/java/com/featureprobe/sdk/example/FeatureProbeDemo.java file with an editor.

  1. Open the FeatureProbe platform project list page, you can click Projects on the toggle details page to open: project

  2. Copy Server SDK Key. sdk key

  3. Fill in Server SDK Key and FeatureProbe remote URL ("https://featureprobe.io/server") into the corresponding variables of the backend code.

src/main/java/com/featureprobe/sdk/example/FeatureProbeDemo.java
    private static final String FEATURE_PROBE_SERVER_URL = "https://featureprobe.io/server";
private static final String FEATURE_PROBE_SERVER_SDK_KEY = // Fill in the server SDK key
  1. Add the following code. Simulate 1000 users accessing the toggle. Among the users whose toggle return value is true, 55% of them report custom events, and among users whose toggle return value is false, 45% of them report custom events.
src/main/java/com/featureprobe/sdk/example/FeatureProbeDemo.java
    public static void main(String[] args) throws IOException, InterruptedException {

Logger root = (Logger)LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.WARN);

final FPConfig config = FPConfig.builder()
.remoteUri(FEATURE_PROBE_SERVER_URL)
.build();

// Init FeatureProbe, share this FeatureProbe instance in your project.
final FeatureProbe fpClient = new FeatureProbe(FEATURE_PROBE_SERVER_SDK_KEY, config);

final String YOUR_TOGGLE_KEY = "custom_event";
final String YOUR_EVENT_NAME = "test_event";

for (int i = 0; i < 1000; i++) {
FPUser user = new FPUser().stableRollout(String.valueOf(System.nanoTime()));
boolean newFeature = fpClient.boolValue(YOUR_TOGGLE_KEY, user, false);
Random random = new Random();
int randomRang = random.nextInt(100);
if (newFeature) {
if (randomRang <= 55) {
fpClient.track(YOUR_EVENT_NAME, user);
}
} else {
if (randomRang > 55) {
fpClient.track(YOUR_EVENT_NAME, user);
}
}
Thread.sleep(300);
}

fpClient.close();
}
  1. Run the program.
mvn package
java -jar ./target/server-sdk-java-1.4.0.jar

Control the front-end program

We provide a front-end js code example, and you can start to experience how the front-end code report custom event.

Write code

  1. Clone the code.
git clone https://github.com/FeatureProbe/client-sdk-js.git
cd client-sdk-js
  1. Open platform to get client sdk key.
info

Click the "Projects" tab to enter the "Projects" list, obtain various SDK keys, and modify service and environment information.

client sdk key

  1. Open example/index.html and fill in Client SDK Key and FeatureProbe URL ("https://featureprobe.io/server")
example/index.html
const fpClient = new featureProbe. FeatureProbe({
remoteUrl: "https://featureprobe.io/server",
clientSdkKey: // Paste client sdk key here,
user,
refreshInterval: 5000,
});
  1. Add the following code. Simulate a lot of users are accessing the toggle. Among the users whose toggle return value is true, 55% of them report custom events, and among users whose toggle return value is false, 45% of them report custom events.
example/index.html
<script>
const user = new featureProbe.FPUser();

const fpClient = new featureProbe.FeatureProbe({
remoteUrl: "https://featureprobe.io/server",
clientSdkKey: // Paste client sdk key here,
user,
refreshInterval: 1000,
});

const YOUR_TOGGLE_KEY = "tutorial_rollout";
const YOUR_EVENT_NAME = 'test_event';

fpClient.waitUntilReady().then(() => {
const boolValue = fpClient. boolValue(YOUR_TOGGLE_KEY, false);
const random = Math.floor(Math.random() * (100 - 1) + 1);

if (boolValue) {
if (random <= 55) {
fpClient.track(YOUR_EVENT_NAME);
}
} else {
if (random > 55) {
fpClient.track(YOUR_EVENT_NAME);
}
}

// Reload page to simulate a new user visiting the page
setTimeout(() => {
location.reload();
}, 1100);
})

fpClient.start();

</script>

Validate results

Open the Analysis Tab on platform to view the result. result