Add a library
Download a library and add it to Gradle as below.
implementation files('libs/netfunnel-android-agent_latest.aar')
Settings initialization
To apply the agent, you must initialize the Netfunnel agent's settings using the separately provided initialization function.
Use InitNetFUNNEL, InitEum functions to initiate before using the NetFUNNEL.
public void Init() {
Netfunnel.InitNetfunnel(
"MyAppName", // MyAppName: Name of the application
"{tenant API URL}", // API Server URL
"{tenant NF URL}", // NetFUNNEL Server URL
"{nf-setting URL}", // NetFUNNEL Setting File URL
"{network Timeout}" // Max timeout for the NetFUNNEL request
this // Activity for Creating a Waiting/Blocking room
);
/*
* 1. Eum Server URL (Same As Netfunnel Server URL), 2. activity(to collect device info)
*/
Netfunnel.InitEum(
"{EUM Server URL}", // EUM Server URL: Server URL for EUM
"{timeout}" // Max timeout for EUM request
this // Activity
);
Netfunnel.getInstance().InitEum(tenantAPINFURL, 2000,this) // EUM Settings
Netfunnel.getInstance().EUMCollectYN(true) // Whether to collect EUMs
}
Traffic Control Settings
Implementing the callback fucntion after waiting
In a virtual waiting room, callback functions are called depending on the situation when the wait ends. Depending on the type of callback function, you can handle successful entry and blocking, and you can implement a callback function when the wait is canceled to implement different user scenarios that occur when entry is blocked and the wait is canceled.
The callback functions are defined in the AgentInterface class, an interface whose behavior is defined in response to NetFUNNEL control responses. You can inherit the AgentInterface class from a separate class and implement the internal callback functions, or you can implement the internal callback functions from the constructor of the AgentInterface class as shown below.
Implementing the callback function using AgentInterface class constructor
AgentInterface agentInterface = new AgentInterface() {
@Override
public void onSuccess() {
/*
* Called when the wait is over and entry is successful,
or when the request fails due to a problem with the netfunnel server itself.
*/
}
@Override
public void onCancel() {
/*
* Called when the Cancel Wait button is clicked on the waiting room.
*/
}
@Override
public void nfLog(String _message) {
/*
* The logs written by the Netfunnel library are called.
* like DLog.d(_message)
*/
}
@Override
public void onNetworkDisconnect() {
/*
* Called when a request to the NetFunnel server fails,
but the reason is that the device's network is blocked.
*/
}
@Override
public void onKeyError() {
/*
* Called when a request is made with a key that has already expired, does not exist, or is invalid.
*/
}
@Override
public void onBlock() {
/*
* Called when the project access mode is set to Disabled in the Admin Console.
*/
}
@Override
public void onIpBlock() {
/*
* Called if blocked by the macro blocking feature due to frequent requests from the admin console.
*/
}
};
Implementing callbacks that are called on successful entry
There are two implementations for a successful entry.
- Code to enter the target page
- Call the completion handling function to perform the process of returning the issued key to the NetFUNNEL server
Completion functions
Function type | Name | Argument | Description |
Completion function | NFStop | projectKey |
The project key can be found in the NetFUNNEL console. ex) service_1 |
segmentKey |
The segment key can be found in the NetFUNNEL console when creating a segment. ex) segKey_1234 |
Below is example code that implements the onSuccess() callback function.
AgentInterface agentInterface = new AgentInterface() {
@Override
public void onSuccess() {
// Execute the completion function for basic control
Netfunnel.NFStop(projectKey, segmentKey);
// Perform an activity conversion
runOnUiThread(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(CurrentActivity.this, NewActivity.class);
startActivity(intent);
}
});
}
};
Implement a callback to be called when entry is blocked
When entry is blocked, it is usually due to frequent macro requests or requests made maliciously with invalid keys. In this situation, you can implement the following logic to improve the visitor's user experience.
- If they want to stay on the current page: no logic implementation required
- Implement logic to show a separate modal window indicating that entry is blocked.
- Implement logic to navigate to a specific page that indicates entry is blocked.
- Implement logging logic
In the case of a blocked or failed entry, you can implement the same logic as above, and unlike the successful entry case, you don't need to call a separate completion handling function.
Below is an example code that implements the onBlock() callback function.
AgentInterface agentInterface = new AgentInterface() {
@Override
public void onBlock() {
/*
1. If they want to stay on the current page: no logic implementation required
2. Implement logic to show a separate modal window indicating that entry is blocked.
3. Implement logic to navigate to a specific page that indicates entry is blocked.
4. Implement logging logic
*/
}
};
Implement a callback that is invoked when a wait is canceled
If an end user presses the Cancel Wait button while waiting in a virtual waiting room, the Cancel Wait callback can be invoked. In this situation, you can implement the following logic to enhance the visitor's user experience.
- No logic needs to be implemented if they want to stay on the current page.
- Implement logic to show a separate modal window indicating that the wait has been canceled.
- Implement logic to take you to a specific page that shows that the wait has been canceled.
- Implement logging logic
In the case of a canceled wait, you can implement any of the above logic, and unlike the entry success case, it doesn't require a separate completion handling function call.
Below is example code that implements an onCancel callback function that is called when the cancel wait button is pressed.
AgentInterface agentInterface = new AgentInterface() {
@Override
public void onCancel() {
/*
1. No logic needs to be implemented if they want to stay on the current page.
2. Implement logic to show a separate modal window indicating that the wait has been canceled.
3. Implement logic to take you to a specific page that shows that the wait has been canceled.
4. Implement logging logic
*/
}
};
Wait-Start
If you want to apply the virtual waiting room to a specific part of the page (view or activity) where you want to wait for traffic, you can apply the virtual waiting room using a Wait-Start function.
Call the NFStart() function in the part of your code that you want to keep visitors in the NetFUNNEL virtual waiting room.
Netfunnel.NFStart("{project Key}", "{segment Key}", agentInterface);
Comments
0 comments
Article is closed for comments.