Integrating the OptiMonk Campaigns with Webhook

 

The Webhook integration allows you to connect OptiMonk with any marketing software. We recommend using Webhook in case OptiMonk does not have a direct integration with your selected system. It can also be useful when you wish to send more data than we send by default. Please note the Webhook integration requires coding your own webpage. If you do not have a developer, consider using Zapier for the integration, as it does not require any coding knowledge to set up.

How does the Webhook integration work?

A Webhook integration sends certain data to an 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 via POST method:

  • 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])
  • Coupon code (variable: custom_fields[coupon_code], if the campaign template is "Lumira/Vegas")
  • GDPR checkbox value (variable: custom_fields[om_policy_checkbox])

checkbox.png

checkboxom.png

dropdown.png

dropdownom.png

email.png

emailom.png

fname.png

fnameom.png

lname.png

lastnameom.png

radio.png

radiom.png

webhookadatok.png

webhookadatok1.png

https://webhook.site/

Please note: In the case of Webhook, there is no need for any extra marking, therefore the easiest way is to provide the subject's name on the input field within OptiMonk.

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 (file attached to the article): https://www.optimonk.hu/webhook_sample.php

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 at https://app.optimonk.com/login/en

  2. Select Campaigns on the left, then select the Campaign you want to use for Webhook integration:

    mceclip0.png

  3. Select Edit settings on the right:

    mceclip1.png

  4. Click on Add new integration under Add integration:

    mceclip2.png

  5. Select Webhook from the list:

    mceclip3.png

  6. Enter the name of the integration and URL of php sample page: https://www.optimonk.hu/webhook_sample.php in the URL field, then click Done and Next in the top right corner to save the changes:

    mceclip4.png

  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 Webhook integration following the steps above. When the popup is filled, Webhook will send the data to the email address provided.

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 at https://app.optimonk.com/login/en

  2. Select Campaigns on the left, then select the Campaign you want to use for Webhook integration:

    mceclip0.png

  3. Select Edit settings on the right:

    mceclip1.png

  4. Click on Add new integration under Add integration:

    mceclip2.png

  5. Select Webhook from the list:

    mceclip3.png

  6. Open https://hookbin.com/ and click on Create new Endpoint:

    mceclip5.png

  7. Copy the Bin URL:

    mceclip5.png

  8. Return to the OptiMonk dashboard and paste the URL:

    mceclip6.png
    Give a name to the integration, then click Done and Next in the top right corner to save the changes.

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 set up correctly, you should see data like this:

3._eng.JPG

You can find the data sent by OptiMonk in Body

Have more questions? Submit a request

Comments