Google Ads转化跟踪与React

huangapple go评论54阅读模式
英文:

Google Ads Conversion Tracking With React

问题

以下是您要翻译的内容:

"I'm attempting to add Google Ads conversion tracking within a React App. In this situation I need to set it up to trigger on click as opposed to page URL. Within the index.html I added the Google Tag and the Conversion Event Snippet without issues.

My Question: How do I now call the function on a React Component to trigger a conversion?



Event Snippet:


"

英文:

I'm attempting to add Google Ads conversion tracking within a React App. In this situation I need to set it up to trigger on click as opposed to page URL. Within the index.html I added the Google Tag and the Conversion Event Snippet without issues.

My Question: How do I now call the function on a React Component to trigger a conversion?

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-______"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'AW-______');
</script>

Event Snippet:

<!-- Event snippet for Payment conversion page
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-_____/_____',
      'transaction_id': '',
      'event_callback': callback
  });
  return false;
}
</script>

答案1

得分: 0

在React组件中,您可以通过以下方式在单击时使用window.gtag触发Google Ads转化。

第一个AW-________号码来自您的Google标签。

第二个AW-_______/________号码来自您的事件片段。

const clickedButton = () => {

    // 这将触发转化

    window.gtag('config', 'AW-_______');

    window.gtag('event', 'conversion', {'send_to': 'AW-______/____________'});
    
}
英文:

Within a React component you can trigger a Google Ads conversion on click by using window.gtag as shown below.

The first AW-________ number is from your Google Tag.

The second AW-_______/________ number is from your Event Snippet.

const clickedButton = () => {
   
//This will trigger the conversion 

window.gtag('config', 'AW-_______');

window.gtag('event', 'conversion', {'send_to': 'AW-______/____________'});

}

huangapple
  • 本文由 发表于 2023年3月4日 08:43:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75632968.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定