问题
I want to integrate Google conversion Adwords code in Contact form 7 Plugin without redirecting to a ‘Thank You’ page.How to implement Google Adwords conversion code in Contact form 7 Plugin.Could someone help me.I would not prefer redirecting to another page.
回答1:
I found solution for implementing Google conversion Adwords code in Contact form 7.
Step 1 Edit the CF7 form you want to track conversions for and paste the Google Adwords Conversion code from google at the end of your form.
Step 2
Replacing on_sent_ok with DOM Events.
To replace it with an alternative code using DOM events, first, find the file named “functions.php” in the directory of your active theme. Second, add the following code at the bottom of the functions.php file:
add_action( 'wp_footer', 'mycustom_wp_footer' );
function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
typeof goog_report_conversion === 'function' && goog_report_conversion();
}, false );
</script>
<?php
}
Step 3
Remove the “on_sent_ok” line from the Additional Settings tab and save the contact form.
来源:https://stackoverflow.com/questions/47279181/how-to-implement-google-adwords-conversion-code-in-contact-form-7-wordpress