最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to embed gtag GA4 event in a div when loaded? - Stack Overflow

programmeradmin2浏览0评论

We use GTM for our GA4 config tag and events. However, the CRM site doesn't integrate with GA4. While we have our GTM container installed on it, it hasn't been super reliable to look for the visibility of a thank you message after submitting an important form. The DBA configures the thank you messages and I recently learned that we can include javascript and html in those thank you messages, which would be more reliable.

How would I get a GA4 event to fire when the message is displayed on the page (whether or not the user scrolls to see it))? Do I just embed the gtag('event','eventname'); code in tags within the message ? Does it need any other code to trigger it? Could there be timing issues if the GA4 config tag isn't fired first from the GTM container (it's set to trigger on Initialization)?

I'm not a webdev or programmer, so looking for basic info.

To test it out, I edited a test page on our wordpress site and added: <script> gtag('event', 'test_inline_ga_event'); </script> into a random content . But in the console it says "Uncaught ReferenceError: gtag is not defined." Timing issue with the GA4 config tag? Because I see other GTAG commands (from gtm) firing just fine afterwards. How can I be sure to only fire the command after the GA4 config tag has run?

Thanks! Jannette

发布评论

评论列表(0)

  1. 暂无评论