RPI web client advanced initialization concepts
Overview
This section details an advanced initialization feature when using the RPI Web Client: the ability to call a function immediately after the client initializes. This allows you to include additional code that is not part of the WebClient but uses features of the web client.
In this example, we are using the post initialization function to generate a web event related to double opt in. The function determines if a query string parameter exists, and if it does it generates a web event using the RPIWebClient. The query string parameter would be added to the URL as part of an outbound campaign. In this example, we are focusing on the post initialization function and not how to append the query string parameter using RPI outbound.
Calling a post initialization function
As a part of the initialization of the client, you can include a post initialization function. You include the notation ( ) =>
followed by the name of the function to call. The function could be included in the call, but it is cleaner to break out the code in a separate function. Below is an example where we initialize the client and then call the function postInit()
after the client is initialized.
script type="text/javascript">
//Initalize the web client and then call a function called postInit()
rpiWebClient.init({}, () => postInit());
</script>
Post initialization function
The post initialization function is listed below. It is checking to see if the query string parameter "mint"
is populated, and if it is, it checks to see if the value is double_opt_in
or double_opt_in-hipaa
. If it is either of those, then it will use the rpiWebClient to push a web event with the Event Name of "Message_Intent"
and capture the value of the query string parameter as the Event Detail along with a few other query string parameters as metadata of the event.
<script type="text/javascript">
function postInit() {
if (rpiWebClient && rpiWebClient.isInitialized) {
//Set form tracking in case a form is added to the page
rpiWebClient._setFormTracking();
//Check the URL parameters to determin if the parameter mint is related to double opt in and if so then generate a web event to capture the double opt in. This process is expecting that the double opt in message is generated from a form submission fsid.
const urlParams = new URLSearchParams(location.search);
if (
urlParams.get("mint") === "double_opt_in" ||
urlParams.get("mint") === "double_opt_in-hipaa"
) {
console.log("If mint equals: " + urlParams.get("mint"));
//Submit Realtime Web Event for Double Opt In
rpiWebClient.pushWebEvent(
"Message_Intent",
1,
urlParams.get("mint"),
null,
[
{ Name: "SVID", Value: urlParams.get("svid") },
{ Name: "FSID", Value: urlParams.get("fsid") },
{ Name: "EMID", Value: urlParams.get("emid") },
]
);
}
}
}
</script>
This is just one way that the post initialization function can be used, but overall demonstrates the post initialization functionality.