• Resolved Anuj

    (@anujmakhloga)


    Getting this error – “unexpected token < in JSON at position 0” while adding analytics amp code in the amp settings.

    <script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
    <amp-analytics type="gtag" data-credentials="include">
    <script type="application/json">
    {
      "vars" : {
        "gtag_id": "UA-137248216-2",
        "config" : {
          "UA-137248216-2": { "groups": "default" }
        }
      }
    }
    </script>
    </amp-analytics>
Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi there,

    In order to add the Analytics snippet you don’t need to add the amp-analytics component or the script tag. The below is sufficient:

    {
      "vars" : {
        "gtag_id": "UA-137248216-2",
        "config" : {
          "UA-137248216-2": { "groups": "default" }
        }
      }
    }

    Please also ensure you input googleanalytics as the type.

    As opposed to using the Analytics tab within the AMP plugin you may prefer to use the Site Kit plugin. This can insert your Analytics snippet on both your AMP and non AMP URLs, removing the need to use the AMP plugins Analytics tab if using Google Analytics.

    Thread Starter Anuj

    (@anujmakhloga)

    Thank you, sir.

    No errors while saving the code …but still amp pages aren’t showing in analytics

    No problem, happy to help.

    If you check your Analytics real time report you should see traffic when visiting your own site. If not feel free to share a video recording using a service such as Loom or RecordIt, showing a visit to your site while also showing your Analytics real time report (for that connected property)

    If you’re having trouble you can also use the Site Kit plugin however I have checked and your Analytics setup seems correct.

    Thread Starter Anuj

    (@anujmakhloga)

    Still not working. Here’s the link analytics error

    Thanks for sharing, very useful indeed. Rather than manually inserting your Google Analytics snippet can you try to use the Site Kit plugin and allow the plugin to insert your Analytics snippet for you? Before doing so please remove your existing Analytics snippet from within the AMP plugin.

    You’ll find instructions on how to setup Site Kit and connect Analytics on the Site Kit plugin website.

    After setting up Site Kit with Analytics please check your Analytics live report once more. When doing so please ensure you’ve checking your site visits while not logged in, preferably from a Chrome browser incognito window. The default configuration within Site Kit for Analytics is to not count logged in users. When checking the real time report if sharing a recording once more please also show the same Analytics property so we can confirm this is valid.

    Thread Starter Anuj

    (@anujmakhloga)

    This code helped me –

    {
    	"vars": {
    		"account": "?? Provide site tracking ID here (e.g. UA-XXXXX-Y) ??"
    	},
    	"triggers": {
    		"trackPageview": {
    			"on": "visible",
    			"request": "pageview"
    		}
    	}
    }

    I don’t know but this seems different from the above mentioned code. it’s working fine though.

    Thank you.

    Great to hear it, thanks for providing an update.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘unexpected token < in JSON at position 0’ is closed to new replies.