Created
September 20, 2023 02:01
-
-
Save stacklast/dad3608aec0b9e7b0c5400caa7866be2 to your computer and use it in GitHub Desktop.
gtag event for button from wordpress plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- Event snippet for whatsapp conversion page --> | |
| <script> | |
| function gtag_report_conversion(url) { | |
| var callback = function () { | |
| if (typeof(url) != 'undefined') { | |
| window.location = url; | |
| } | |
| }; | |
| gtag('event', 'conversion', { | |
| 'send_to': 'AW-XXXXXXXXX/XXXXX-XXXXXXXXXX', | |
| 'event_callback': callback | |
| }); | |
| return false; | |
| } | |
| function conversionBtn(event){ | |
| document.getElementById("whatsapp").addEventListener("click", function () { | |
| gtag_report_conversion('https://web.whatsapp.com/send?text=&phone=9999999999'); | |
| event.preventDefault() | |
| }); | |
| } | |
| if(window.attachEvent) { | |
| window.attachEvent('onload', conversionBtn); | |
| } else { | |
| if(window.onload) { | |
| var curronload = window.onload; | |
| var newonload = function(evt) { | |
| curronload(evt); | |
| conversionBtn(evt); | |
| }; | |
| window.onload = newonload; | |
| } else { | |
| window.onload = conversionBtn; | |
| } | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment