步骤一:添加google跟踪代码
1 2 3 4 5 6 7 8 9 |
<!-- Global site tag (gtag.js) - Google Ads: xxxxxxxxx --> <script async src="https://www.googletagmanager.com/gtag/js?id=AW-xxxxxxxxx"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'AW-xxxxxxxxx'); </script> |
步骤二:添加事件代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<!-- Event snippet for conversion name In your html page, add the snippet and call gtag_report_conversion when someone clicks on the chosen link or button. --> <script> 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; } </script> |
步骤三:添加Click属性
1 2 |
<a onclick="return gtag_report_conversion('http://example.com/your-link');" href="http://example.com/your-link">Download now!</a> |
另一种方法1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<!-- Event snippet for conversion name --> In your html page, add the snippet and call gtag_report_conversion when someone clicks on the chosen link or button. --> <script> 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; } </script> <script type="text/javascript"> jQuery(document).ready(function($){ $('.google_ads_link').on('click', function(e){ gtag_report_conversion($(this).attr('href')); }) }); </script> |
另一种方法2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<script> function gtag_report_conversion(url){ var callback = function () { if (typeof(url) != 'undefined') { window.location = url; } }; gtag('event', 'conversion', { 'send_to': 'AW-.....', 'event_callback': callback }); return false; } document.getElementById("your-form-id").onsubmit = function(){ gtag_report_conversion(); }; </script> |
标签:googe竞价
总共0 条评论。