3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
目錄 Original Post Add A Google Ads Conversion Tracking Tag To Your WordPress Website For Conversions And Conversion Value Bidding Strategy There are several bidding strategies available in Google Ads, including conversion, conversion value, clicks, etc. If you want to choose conversions, then conversion tracking tag will be essential. Add Global Site Tag There are two parts of conversion tracking code that you have to add to your website. First is the global site tag(gtag.js), which is unique and for all conversions. The second part is the event snippet, and it should be installed for each conversion tracking. Both codes can be found in the Google Ads > Tools & Settings (At the right top of the page) > Conversion. Of course, you have to create a tracking conversion first. gtag.js will be like as below, and you have to insert it between the and tag. You can manually add it to your WordPress theme, through Google Tag Manager, or with a plugin. window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'AW-xxxxxxxxx'); Add Event Snippet After setting up the global site tag, we can take a look at the event snippet. function gtag_report_conversion(url) { var callback = function () { if (typeof(url) != 'undefined') { window.location = url; } }; gtag('event', 'conversion', { 'send_to': 'AW-xxxxxxxxx/XXXXXXXXXXXXXXXX', 'value': 10.0, 'currency': 'TWD', 'event_callback': callback }); return false; } In your html page, add the snippet and call gtag_report_conversion when someone clicks on the chosen link or button. Generally, we don’t want to track conversions on every page, so it is inappropriate to insert the event snippet to the head tag. As google official document said, you can add an onclick attribute to trigger the conversion event. Download now! If you use Gutenberg as your WordPress editor, you can switch the block to HTML mode, then add the code. However, if you use the classic editor, or you want to add it to a WooCommerce product page, the onclick attribute will be removed automatically after saving. I guess it is for a security purpose. Alternatively, we can complete it with post_meta. There are two steps. Step 1. Add Post_Meta Between Head Tag Between head tag, add the php code as below. It will display blank if the post doesn’t have a post_meta named google_ads_conversion. Step 2. Create A Post_Meta By default, admins can add a post meta on the edit page. Create it and paste the event snippet. Of course, you can name it everything, but remember to match with the post_meta key(like google_ads_conversion above). Another point is I added a jQuery event to trigger gtag function. Again, you can change the selector (.google_ads_link below) as you want, but remember to add a class, or id, or title in the editor to ensure it works. In your html page, add the snippet and call gtag_report_conversion when someone clicks on the chosen link or button. --> function gtag_report_conversion(url) { var callback = function () { if (typeof(url) != 'undefined') { window.location = url; } }; gtag('event', 'conversion', { 'send_to': 'AW-xxxxxxxxx/XXXXXXXXXXXXXXXX', 'value': 10.0, 'currency': 'TWD', 'event_callback': callback }); return false; } jQuery(document).ready(function($){ $('.google_ads_link').on('click', function(e){ gtag_report_conversion($(this).attr('href')); }) }); Related Posts Learn Python And R On DataCamp. Start Your Data Science Career. A Aron Data analyst, but building WordPress websites, having experience in digital marketing. Recently dives into fighting and Python quantitative investment.

本文由aronhackcom提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦