Post custom cookie values into form, and UTM values as a fallback?

By: Jeremy Alexander | Asked: 01/19/2023
ForumsCategory: Code HelpPost custom cookie values into form, and UTM values as a fallback?
Jeremy Alexander asked 2 years ago

Hello! I'm trying to map this process used on another form to get formidable to post their unique cookie values into the specified fields, with UTMs as a fallback (default direct when both are missing) -- but can't wrap my head around it.  Does anyone have experience with this? Help would be greatly appreciated T_T   

 

$url = $_COOKIE['UTMSession'];
parse_str($url, $Utmarray);
$utm_source = $utm_medium = $utm_content = $utm_campaign = $utm_term = ''; if (array_key_exists("utm_source", $Utmarray)) {
$utm_source = $Utmarray['utm_source'];
}
if (array_key_exists("utm_medium", $Utmarray)) {
$utm_medium = $Utmarray['utm_medium'];
}
if (array_key_exists("utm_content", $Utmarray)) {
$utm_content = $Utmarray['utm_content'];
}
if (array_key_exists("utm_campaign", $Utmarray)) {
$utm_campaign = $Utmarray['utm_campaign'];
}
if (array_key_exists("utm_term", $Utmarray)) {
$utm_term = $Utmarray['utm_term'];
}
// check through Url Query Parameters
if (array_key_exists("utm_source", $getQueryParams)) {
$utm_source = $getQueryParams['utm_source'];
}
if (array_key_exists("utm_medium", $getQueryParams)) {
$utm_medium = $getQueryParams['utm_medium'];
}
if (array_key_exists("utm_content", $getQueryParams)) {
$utm_content = $getQueryParams['utm_content'];
}
if (array_key_exists("utm_campaign", $getQueryParams)) {
$utm_campaign = $getQueryParams['utm_campaign'];
}
if (array_key_exists("utm_term", $getQueryParams)) {
$utm_term = $getQueryParams['utm_term'];
}

$data['Source'] = $utm_source;
$data['Medium'] = $utm_medium;
$data['Content'] = $utm_content;
$data['Campaign'] = $utm_campaign;
$data['searchTerm'] = $utm_term;

Mark HansenMark Hansen replied 1 year ago

Hi! I had to jump through some hoops to get our tracking working properly on a client site. I ended up using this page as a resource to get me started. https://github.com/scottious/google-analytics-dissection

I got it working in the end, and all data passes through to our hidden form fields, tracks perfectly, and is able to submit to SalesForce for internal tracking.

I hope it helps.

Mark

Jeremy Alexander replied 1 year ago

Mark this is stellar! Thank you so much!!

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right