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.