Sending data to GA from new record hook
-
I’m trying to execute a script inside elementor_pro/forms/new_record but I’m getting parse error, I tried resetting the response after executing the script but all I get is the script sent as a response and it doesn’t get executed anyway I can achieve this ?
// Sending data to GA //add_action( 'elementor_pro/forms/new_record', 'pass_data_to_GA', 10, 2); function pass_data_to_GA( $record, $handler ) { //make sure its our form $form_settings = $record->get('form_settings'); $form_id = $form_settings['form_id']; $raw_fields = $record->get( 'fields' ); $fields = []; foreach ( $raw_fields as $id => $field ) { $fields[ $id ] = $field['value']; } $name = $fields['name']; $email = $fields['email']; $fullno = $fields['phone']; error_log(json_encode($name)); ?> <script> if(jQuery("div.elementor-message-success").length) { // window.dataLayer = window.dataLayer || []; // window.dataLayer.push({ // event: "formSubmission", // formID: <?php echo $form_id;?>, // fullName: <?php echo $name;?>, // phone: <?php echo $fullno;?>, // email: <?php echo $email;?>, // }); console.log("test") // submit an event to Google Analytics ga('send', 'event', <?php echo $form_id;?> , 'Submit'); } </script> <?php $handler = null; $response = "The form was sent successfully."; $handler->is_success = true; $handler->add_response_data(true, $response); return $handler; }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Sending data to GA from new record hook’ is closed to new replies.