Hello,
I'm attempting to catch the cookie data from google-analytics utm.gif and pass those values to gravity forms which has the sales force add-on. Here is my code:
I have several inquiries about the performance. This code does catch the cookie, and pass the value. In this case $_POST[ 'input_3' ] is the hidden field we are giving the value for one of the GA parameters.
I need to replicate this same functionality for about a dozen forms, not just form with the id of 39. I need to create hidden inputs for each of the forms and i'm assuming they will all have a unique name attribute and therefore seems like I will need to create a custom function for each one to give value to. Is there a better way about programming this so that its more automated and does not require me to edit the script if hidden fields are added/removed or new forms are created?
I am trying to streamline this as best as possible for a client
class GA_Tracking {
function __construct( ) {
add_action( 'gform_pre_submission_39', array( &$this, 'form_39' ) );
}
function cookie( ) {
if( $cookie = $_COOKIE[ '__utmz' ] ) {
function strnpos( $haystack, $needle, $occurance, $pos = 0 ) {
for ( $i = 1; $i <= $occurance; $i++ ) {
$pos = strpos( $haystack, $needle, $pos ) + 1;
}
return $pos;
}
$paramsstr = substr( $cookie, strnpos( $cookie, '.', 4 ) );
$params = explode( '|', $paramsstr );
$param = array( );
foreach( $params as $key => $value ) {
$split = explode( '=', $value );
$param[ $split[ 0 ] ] = $split[ 1 ];
}
}
return $param;
}
function form_39( ) {
$param = $this->cookie( );
$_POST[ 'input_3' ] = $param[ 'utmcsr' ];
}
}
$gat = new GA_Tracking;