Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epicmatt/c010b8bb1fd7df243b2a05ce74e229a6 to your computer and use it in GitHub Desktop.
Save epicmatt/c010b8bb1fd7df243b2a05ce74e229a6 to your computer and use it in GitHub Desktop.
Add Cookies data to webhook
<?php
/**
*
* Plugin Name: CF7 to Webhook - Add UTM Cookies
* Description: Add Cookies data to webhook
* Version: 1.0.2
* Author: Mário Valney - Modified for Handl UTM Grabber by Epic Matt
* Author URI: https://mariovalney.com + Modified by https://epicim.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 "HANDL UTM GRABBER"
* and add to CF7 to Webhook data.
*
* @see wp-content/plugins/handl-utm-grabber/handl-utm-grabber.php
*
* @param $data array 'field => data'
* @return $data
*/
function ctz_add_cookies_to_data_from_contact_form( $data ) {
$data['gclid'] = empty( $_COOKIE['gclid'] ) ? '' : $_COOKIE['gclid'];
$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['handl_ip'] = empty( $_COOKIE['handl_ip'] ) ? '' : $_COOKIE['handl_ip'];
$data['handl_original_ref'] = empty( $_COOKIE['handl_original_ref'] ) ? '' : $_COOKIE['handl_original_ref'];
$data['handl_landing_page'] = empty( $_COOKIE['handl_landing_page'] ) ? '' : $_COOKIE['handl_landing_page'];
$data['handl_ref'] = empty( $_COOKIE['handl_ref'] ) ? '' : $_COOKIE['handl_ref'];
$data['handl_url'] = empty( $_COOKIE['handl_url'] ) ? '' : $_COOKIE['handl_url'];
$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