• I followed the directions on Google Adwords, which told me to go to my child theme and add some code. (actually I used this site too: https://kinsta.com)

    Here is the error it returned:
    syntax error, unexpected ‘<‘, expecting end of file

    Here is the code I tried to put into the child theme’s function.php file. Apparently this is how you put the code in the Head area.

    /* Google Adwords conversion tracking */
    
    <!-- Global site tag (gtag.js) - Google Ads: 981117273 -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=AW-xxxxxxxx"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
    
      gtag('config', 'AW-981117273');
    </script>
    
    <!-- Event snippet for TofA tracking 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-xxxxxxxx/xxxxxx',
          'event_callback': callback
      });
      return false;
    }
    </script>
    
    

    I tried to ask in the Google Community but it saw the code and would not allow me to upload it. It gave me an error message and would not allow me to post. So WP does not like it and Google Community does not like it too.

    Any ideas how I can make this work, or do I have to get a “tag” plugin?

    This is line 29:
    <!– Global site tag (gtag.js) – Google Ads: 981117273 –>

    It is the line that WP calls out as bad, it is possible there is more if WP saw the first error and did not check the rest of the file.

    How do I fix it, please?

    Thanks for considering this question

    • This topic was modified 5 years, 11 months ago by lucabrasi40.
    • This topic was modified 5 years, 11 months ago by lucabrasi40.
    • This topic was modified 5 years, 11 months ago by lucabrasi40.
    • This topic was modified 5 years, 11 months ago by Jan Dembowski.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Stefano

    (@madking-web-design)

    Hi @lucabrasi40 !

    You added the code to the wrong file, this is a piece of code that should load in the header of your theme.
    So in your case, I suggest an easier solution.
    Install a plugin that will automatically add your Google Conversion Tracking code in your theme.
    The plugin you will need is Head, Footer and Post Injections
    1) install the plugin and activate it.
    2) Go to Settings → Header and Footer (Screenshot)
    3) paste the code in one of the boxes under the <HEAD> SECTION INJECTION area
    Done.

    If you want manually add the code in functions.php and not use a plugin, is a bit more complicated, so I would suggest to do it the easy way I described.
    However, if you want to do that, then you need to follow the 2nd solution in this article

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Moved to Fixing WordPress, this is not a Developing with WordPress topic.

    Thread Starter lucabrasi40

    (@lucabrasi40)

    THanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Google Conversion Tracking code’ is closed to new replies.