How to integrate with Webhook

1. When should I use the Webhook integration?

Our Webhook integration allows you to connect OptiMonk with virtually any marketing software, including those which are not included in our list of integrations. It can also be useful when we have the integration you need on our list, but you want to send more data than we send by default. For example, when you want to send the URL of the source page or another custom field. Please note the Webhook integration is an advanced integration which requires coding your own PHP.

2. How does the Webhook integration work?

A Webhook integration sends certain data to a PHP URL you provide in the integration settings in your OptiMonk dashboard. After a visitor completes a form in one of your popups with a Webhook integration, the following data is sent by default:

  • First name (variable: firstname)
  • Last name (variable: lastname)
  • Email address (variable: email)
  • URL address (variable: URL)
  • Campaign name (variable: campaign[name])
  • Campaign ID (variable: campaign[id])

3. PHP Sample page

Here’s an example of a PHP page you would create and the corresponding URL that you would enter into your OptiMonk dashboard for the Webhook integration. This sample page sends the data received from Webhook to the email address given when signing up or any other predefined email address.

Source code of the sample page:

<?php
echo "OptiMonk Webhook Test";
$emailAddress = "";

$webhookContent = "";
// get webhook data
$webhook = fopen('php://input', 'rb');
while (!feof($webhook)) {
    $webhookContent .= fread($webhook, 4096);
}
fclose($webhook);

// convert webhook data to Subscriber array
$rawData = explode("&", urldecode($webhookContent));
foreach ($rawData as $field) {
    $temp = explode("=", $field);
    $subscriber[$temp[0]] = $temp[1];
}

// set subject and recipient
if ( $emailAddress != "") {
    $to = $emailAddress;
    $subject = "New Subscriber!";
} else {
    $to = $subscriber["email"];
    $subject = "[OptiMonk Webhook test] Thank you for subscribing!";
}

$body = "Subscriber data: \n\r";

// write subscriber data in email body
foreach ($subscriber as $key => $value) {
    $body .= $key . ": " . $value . "\n";
}

// send mail
mail($to, $subject, $body);
die;
?>

URL of the sample page: https://www.optimonk.hu/webhook_sample.php

4. Testing the Webhook integration with the PHP sample page

Here’s how to test the Webhook integration using the OptiMonk php sample page:

1. Log in to your OptiMonk dashboard

2. Create a new campaign or select the campaign where you want to use Webhook integration, then go to the Campaign Settings page

3. Scroll down to the Integrations section, and click on the arrow to open the section labeled: Where would you like to keep the list of subscribers? Click on Set up to the right of External System (Transfer subscribers into the following system); this will open a new window with the list of available integrations. Choose Webhook from the list of integrations. The window will close, and you will be returned to the Campaign Settings page in your OptiMonk dashboard

4. Enter the URL of php sample page: https://www.optimonk.hu/webhook_sample.php in the URL field under Settings. Then, scroll to the top of the Campaign Settings page and click on the Save button to save your changes.

5. Test the settings by completing a popup for this campaign on your website. Please note: if you have multiple campaigns on your site, make sure you are triggering the campaign which you updated with the Webhook integration following the steps above. When the popup is filled, Webhook will send the data to the email address provided.

 

5. Testing the Webhook integration with hookbin.com:

Here’s another way you can test the Webhook integration by using the website hookbin.com:

1. Log in to your OptiMonk dashboard

2. Create a new campaign or select the campaign where you want to use Webhook integration, then go to the Campaign Settings page

3. Scroll down to the Integrations section, and click on the arrow to open the section labeled: Where would you like to keep the list of subscribers? Click on Set up to the right of External System (Transfer subscribers into the following system); this will open a new window with the list of available integrations. Choose Webhook from the list of integrations. The window will close, and you will be returned to the Campaign Settings page in your OptiMonk dashboard.

4. Open a separate browser window or tab and visit: http://hookbin.com

5. Click on Create New Endpoint, then copy the Bin URL.

1._eng.JPG

6. Return to the tab or window with the Campaign Settings page in your OptiMonk dashboard and paste the URL from in in the URL field under Settings. Then, scroll to the top of the page and click on the Save button to save your changes.

2._eng.JPG

7. Test the settings by completing a popup for this campaign on your website. Please note: if you have multiple campaigns on your site, make sure you are triggering the campaign which you updated with the in URL following the steps above. Once you’ve completed the popup, refresh the page at HookBin. When everything is setup correctly, you should see data like this:

3._eng.JPG

8. You can find the data sent by OptiMonk in Body

Have more questions? Submit a request

Comments

Powered by Zendesk