目錄
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.
Add Event Snippet
After setting up the global site tag, we can take a look at the event snippet.
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. -->
Related Posts
Learn Python And R On DataCamp. Start Your Data Science Career.
Data analyst, but building WordPress websites, having experience in digital marketing. Recently dives into fighting and Python quantitative investment.