Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contact Source. How to pass source or tag variable in URL? #52

Open
Strellman opened this issue Dec 17, 2021 · 4 comments
Open

Contact Source. How to pass source or tag variable in URL? #52

Strellman opened this issue Dec 17, 2021 · 4 comments

Comments

@Strellman
Copy link

It would be really helpful to know how somebody got to our website! We are storing a cookie to indicate which ad, or which person led the contact to us. Now I want to pass that field to DT in the URL so that as the contact submits their form, the dispatcher will know where they came from (possibly a city, a team, or a person).
If someone can at least point me to the section of code, or the variables to set, that would even help. I would like to create a snippet to store this info.

Another approach would be to do the form on the host website and just send the fields to DT somehow.

@Strellman
Copy link
Author

WPFORMS has done a lot of this. See https://wpforms.com/wpforms-hidden-field/
Is there anyway to to pass the WPFORM data to DT?

@corsacca
Copy link
Member

It would be really helpful to know how somebody got to our website!

Agreed. The current webform does not really support a way of doing that.
One solution could be to add a hook to

public function form_submit( WP_REST_Request $request ){
and hook into it with some php code from your server.

Or, you could write your own form and send the fields to D.T. This is possible via the API and the Site to Site like authentication

The webform could support hidden fields. Since we display the form via iframe, updating those fields from the website is challenging. Next upgrade

@Strellman
Copy link
Author

Strellman commented Dec 28, 2021

Thanks Corsacca, that is very helpful. I really don't understand how to add a hook there without forking and maintaining that code, which is beyond me. Is there anyway to add a filter that pulls variables from the url?

Cookies can't be pulled from a different site into DT, but maybe they could be passed as parameters.  What about getting the cookie before generating the iframe and passing it along with referer in the iframe url? Tell me if it makes sense to you. 

This snippet is a shortcode to insert our cookies as tags into the iframe url before it is generated. Usage:
[dt_source]<iframe style="width: 100%; height: 550px;" src="https://example.com/wp-content/plugins/disciple-tools-webform-master/public/form.php?token=c234234234234480" style="width:100%;height:550px" frameborder="0"></iframe>[/dt_source]

//register shortcode
add_shortcode('dt_source','dt_source');

function dt_source($attr, $iframestring = null){
//send DT tag of referer at least
	$tags = 'tags[]='.$_SERVER['HTTP_REFERER'];
//check to see if user has our initial url cookie, send it
	$contact_url = $_COOKIE['contact_url'];
	if (isset($contact_url)) $tags .= ('&tags[]='.$contact_url);
//if user has source cookie send it
	$contact_source = $_COOKIE['contact_source'];
	if (isset($contact_source)) $tags.= ('&tags[]='.$contact_source);
//insert tags before token parameter in $iframestring 
	$tags .= "&token=";
$iframestring = str_replace("token=", $tags, $iframestring);
return $iframestring;
} //end function

//Then on the DT instance use this snippet of code (How do I hook to it?)
//Get tags into DT contact from iframe url
add_filter( "dt_custom_post_create_fields", "dt_post_create_fields", 1, 2 );
function dt_post_create_fields( $fields, $post_type){
//check if we are dealing with a contact
if ($post_type === "contacts"){
	//check if the tags field is already set
	if ( !isset( $fields["tags"] )){
		$tags = sanitize_text_field($_GET['tags'] ); 
			if (isset($tags))  {
			//define the tags field
			$fields["tags"] = $tags;
			}
		}
	}
return $fields;
}


@corsacca
Copy link
Member

corsacca commented Jan 3, 2022

That could possibly work
Step 0 use the campaigns field or create the needed fields in D.T
Step 1 pass the parameters to the iframe
Step 2 read the url parameters via javascript and submit the form with those parameters.
Step 3 Make sure those parameters are passed along in the form_submit() function

The campaigns field (acts like the tags field) might be the right field for this data. And could be supported out of the box.
If the data is different for each contact, then a text field would be better. And step 3 would be more complicated

We'd want to use a field that already exists in D.T or set up a custom field, so we won't need to do anything in dt_post_create_fields. and instead make sure form_submit() in the webform plugin gets and sends the right data

kodinkat added a commit to kodinkat/disciple-tools-webform that referenced this issue Jan 24, 2022
corsacca pushed a commit that referenced this issue Jan 26, 2022
* Added shortcodes support

* Refactored form html generation logic

* Added support for additional campaigns metadata within url (#52)

* Added functionality tweaks within shortcode handler function

* Added ability to specify campaign values within shortcode embedded form urls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants