Skip to content

Instantly share code, notes, and snippets.

@mariovalney
Last active June 9, 2021 18:55
Show Gist options
  • Save mariovalney/3a3579aae531ecb232be57de29360e9f to your computer and use it in GitHub Desktop.
Save mariovalney/3a3579aae531ecb232be57de29360e9f to your computer and use it in GitHub Desktop.
Add Cookies data to webhook
<?php
/**
*
* Plugin Name: CF7 to Webhook - Add Cookies
* Description: Add Cookies data to webhook
* Version: 1.0.0
* Author: Mário Valney
* Author URI: https://mariovalney.com
* Text Domain: cf7-to-webhook-add-cookies
*/
add_filter( 'ctz_get_data_from_contact_form', 'ctz_add_cookies_to_data_from_contact_form' );
/**
* Get data from cookie like "Easy UTM tracking with contact form 7"
* and add to CF7 to Webhook data.
*
* @see wp-content/plugins/easy-utm-tracking-with-contact-form-7/easy-utm-tracking-with-contact-form-7.php
*
* @param $data array 'field => data'
* @return $data
*/
function ctz_add_cookies_to_data_from_contact_form( $data ) {
$data['utm_source'] = empty( $_COOKIE['utm_source'] ) ? '' : $_COOKIE['utm_source'];
$data['utm_medium'] = empty( $_COOKIE['utm_medium'] ) ? '' : $_COOKIE['utm_medium'];
$data['utm_term'] = empty( $_COOKIE['utm_term'] ) ? '' : $_COOKIE['utm_term'];
$data['utm_content'] = empty( $_COOKIE['utm_content'] ) ? '' : $_COOKIE['utm_content'];
$data['utm_campaign'] = empty( $_COOKIE['utm_campaign'] ) ? '' : $_COOKIE['utm_campaign'];
$data['page_referrer'] = empty( $_SERVER['HTTP_REFERER'] ) ? '' : $_SERVER['HTTP_REFERER'];
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment