Saturday, April 27, 2024

How to make StatCounter AMP compatible in WordPress?

Share

As on AMP (Accelerated Mobile Pages) scripts are not allowed so the <script> code will not be included on amp templates and your StatCounter wont work on these URL’s with amp suffix. There is only a workaround to make this StatCounter analytics code to work on AMP websites. StatCounter team is currently working to make the full java script counter AMP compatible.

Prerequisite: AMP plugin must be already installed on your WordPress website and working properly.

How to make StatCounter AMP compatible in WordPress website?

NOTE: It is always suggested to make a backup of your website before doing any changes.

  • Step 1: Login to your host account and open File Manager
  • Step 2: Go to public_html >> wp-content >> themes >> (YOUR CURRENT THEME) >> mobile
  • Step 3: Now first take backup of header-amp.php and then click on edit
  • Step 4: Paste this part in the <head> section
<style amp-custom>
statcounter {width: 1px;height:1px;}
</style>
  • Step 5: And this part in the <body> section
<div id="statcounter">
<amp-pixel src="https://c.statcounter.com/PROJECT_ID/0/SECURITY_CODE/1/">
</amp-pixel>
</div>

You can now verify the traffic coming to your amp enabled website by looking into the StatCounter logs. If you can see the amp CDN or URL ending with ?amp= , then you have successfully installed the amp version of StatCounter for your WordPress website.

4 COMMENTS

  1. Hi I have went to WP-Content-Themes-My Current Themes but I don’t find Mobile folder nor header-amp.php there. Please tell me what’s wrong?

  2. Hi Yusuf,
    Greetings!
    Please make sure you have the AMP plugin installed and then follow up the same as in above workaround for making the statcounter work in amp pages or posts.

    • I have AMP plugin installed but still no mobile folder nor header-amp.php found by me.

      Anyway I’ve found the solution myself, what I did was simply paste this to widget.

      then stat is counting my visitors. So if anyone want to place the code simply add it to widget (from apperance) and done.

      • Hi Yusuf,
        Great that you got the issue fixed by yourself.
        Most of the Themes have mobile theme version, but it seems its not there for the theme you are using.

        Thanks for the workaround, It will help others also to fix this issue.

Leave a Reply

Read more

More for you