• Resolved Bub

    (@jdenning47)


    For those of you pulling your hair out trying to use a Google Analytics tag with the AMP plugin: I can get a tag to fire if I do the following:

    add_action( ‘wp_body_open’, ‘add_google_tag_manager_noscript_after_body_code’ );
    function add_google_tag_manager_noscript_after_body_code() {
    echo ‘<!– Google Tag Manager (noscript) –>
    <noscript><iframe src=”https://www.googletagmanager.com/ns.html?id=GTM-xxxxxxx&#8221; height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
    <!– End Google Tag Manager (noscript) –>’;
    ?>
    <!– **AMP** for Google Analytics site tag –>
    <amp-analytics type=”gtag” data-credentials=”include”>
    <script type=”application/json”>
    {
    “vars” : {“gtag_id”: “UA-xxxxxxxxx-x”,
    “config” : {“UA-xxxxxxxxx-x”: { “groups”: “default” } }
    }
    }
    </script>
    </amp-analytics>
    <?php
    }

    You must use Universal Analytics so put your own number in place of mine above.
    Google Tag manager still doesn’t work but I just left the code in anyway. It could probably be removed.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Milind More

    (@milindmore22)

    Hello @jdenning47

    Thanks for the information,
    Did you know? you can use AMP plugins analytics settings to add gtag
    following are the steps your can follow

    Step 1) Goto AMP
    Step 2) AMP->Analytics
    Step 3) Click add new (+) button
    Step 4) enter the “type” as gtag
    Stepp 5) replace the ID with your ID

    You can refer to this screenshot

    You can also refer to our guide for more information

    Thread Starter Bub

    (@jdenning47)

    I had thought I tried that and several other code combinations but trying this now using the screen shot example it works as expected. I had been doing a lot of hacking and must have done something not quite correctly. Thanks as now I don’t need to add the code to functions.php anymore.
    NEXT: Can you give me instructions/example and a screen shot for what to do for Google TAG MANAGER too?
    I have been trying what was recommended but Tag Assistant won’t connect. The code shows up in the page source so I must assume I either have some forgotten code artifacts from my previous hacking attempts or I am just using the wrong code. HELP!! and Thanks!!

    • This reply was modified 2 years, 11 months ago by Bub.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to make google analytics tag work. (Really)’ is closed to new replies.