In this article, we’ll learn about the concept of webhooks in VWO, its advantages, how you can enable it, and how you can secure your webhooks.
To better understand the concept of webhooks in VWO FullStack, let's first learn about the settings file.
Whenever you create a FullStack campaign in VWO, a settings file corresponding to your campaign configurations is generated, which you could fetch and cache on your server. If any campaign setting(s) are modified via the VWO app, the settings file stored at your server needs to be updated. This ensures that your campaigns are always running on the latest configurations.
Let's look at the different options that VWO offers to detect the change and update the settings file.
One way to detect the change in the settings file is by polling the VWO servers frequently, and when detected, update the settings file with it. This increases the load on your server as you need to poll the VWO servers at a regular interval, say every ten minutes.
Another way to detect the change in the settings file is by using webhooks. Webhooks in VWO enable you to subscribe to changes. Anytime there is a change in the FullStack campaign settings, VWO sends an HTTP POST call with a payload to the configured URL. Therefore, you know when to fetch the settings file. It helps you to keep the most up-to-date version of the settings file.
With webhooks in place, you don't have to worry whether or not you are using the updated settings file. VWO keeps you up-to-date.
For example, as soon as the traffic allocation percentage of a variation is changed from the app, VWO sends an HTTP POST call with a payload to notify about the change in the campaign settings.
To get notified about the change in the settings file, all you need to do is enable the webhook setting and specify the URL where you wish to receive the change event notification. To know how to do this, refer to Enabling Webhooks in VWO.
Advantages of Using Webhooks in VWO
- Eliminates the need to frequently fetch the latest campaign settings file, reducing the load on your servers.
- Eliminates the possibility of using the old campaign settings file, if not fetched in short intervals.
Enabling Webhooks in VWO
Earlier, VWO used to provide webhooks that notified the changes in the campaign settings at the account-level. However, these notifications were generic and spanned across the environments. This led to guessing which developer environment should be updated whenever you update or create a new A/B test, Feature Test or Feature Rollout. Thereby, VWO has stepped up further to a more granular approach that allows configuring webhooks at environment-level.
Now, you avail the flexibility to configure webhooks individually for each environment. By enabling these webhooks, you will be notified each time a change is made in the campaign settings specific to the given environment. To subscribe to the environment-specific changes, enable the webhooks under the required environment(s).
- Log in to your VWO account.
- From the left panel, go to FULL STACK > Projects and select a project.
- Under the Environment(s) section, select the Enable Webhooks option for those environments that you prefer to subscribe to the changes for.
- In the Webhook URL field, enter the URL where you wish to receive the change event notification.
- To finalize your settings, click Save.
- In case you are an existing user, account-level webhooks will continue to be available if you are already using them. To opt for environment-level webhooks, reach out to email@example.com.
- Once you choose to use environment-level webhooks, the account-level option gets disabled.
- Account-level webhooks will not be available for those availing the webhooks option for the first time.
- If you have account-level webhooks enabled, you can manage them by going to Settings > Campaign > Enable Webhooks section.
Below is the payload format used by VWO.
In case the webhook URL is down (or we receive a non 200 response for the POST request), the webhook would be retried for the next 1 hour after every 1-2 seconds.
Securing Webhooks with API Key-based Authentication
When you set up a public endpoint for updating campaign settings, you may want to protect your webhook to ensure that notifications come from VWO and not from any third-party service trying to trigger the VWO configured webhook manually.
While configuring the webhook in VWO, you can secure it by generating a secret key sent in the x-vwo-auth header of the POST request by VWO. You can then compare this key to ensure that the requests are sent via VWO and not by other third-party services.
On enabling the webhooks in VWO, a secret key is automatically generated along with it. To generate a new secret key for the same, perform the following steps:
- Click the Regenerate Key button. The Regenerate Secret Key dialog appears.
- Click the Generate Key button in the dialog and save the change.