Angular 10 | Google adwords conversion code in head | How to call gtag_report_conversion from...

Discussão em 'Angular' iniciado por Roman, Novembro 6, 2024.

  1. Roman

    Roman Guest

    I have added google adwords conversion code to the head of my index.html:

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

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

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


    The conversion should be counted when a user successfully registers. For this I need to wait for the success message in my register user api endpoint, which is called in a component:

    this.http.post<any>(apiEndpoint, sendData).subscribe(data => {
    console.log(data);

    if (data['error']) {
    this.regError = data['errortxt'];
    } else {
    this.regError = "";
    this.dataService.REG_AUTH = data['data']['token'];
    localStorage.setItem('regauth', data['data']['token']);

    // Adwords Conversion
    gtag_report_conversion(url);

    this.navigation.loadView(this.navigation.getView('3').name);
    }

    }, error => {
    console.log(error.json());
    });


    It tells me Cannot find name gtag_report_conversion(url);

    Any ideas? Somehow I need to import the function from index.html?

    Continue reading...

Compartilhe esta Página