ANALYTICS/JS CODES Breaks AMP

Posted in: Newspaper
Post count: 22

Hello tagDiv Team,

I’ve just updated our dev environment to the latest version of Newspaper + the mobile theme and followed the instructions to do so.

Unfortunately, when I add Analytics and JS code to the site under “ANALYTICS/JS CODES” in the theme settings it leads to AMP failure when checking via Google with many errors. It appears that the mobile theme is attempting to convert the code into amp-friendly without success. As soon as I remove the code from this section all the amp tests pass perfectly.

An example of the code I am using is below:

<script src="//static.getclicky.com/js" type="text/javascript"></script>
<script type="text/javascript">try{ clicky.init(1234); }catch(e){}</script>
<noscript><p>Clicky</p></noscript>

<script async src="//sub.domain.com/js"></script>

Is there any way to tell the mobile/amp theme to ignore these?
If not, could I place directly into the header.php in a child theme?

Thanks

Post count: 22

I’ve tried what I suggested above putting these codes into the header.php of the child theme but unfortunately – this means that the code doesn’t work on mobile OR amp pages. Obviously I need the code to work on mobile but be ignored in amp due to the errors.

Could someone from tagDiv chime in please?

Post count: 22

Is anyone available to help with this?

Post count: 35449

Hi,

Is possible that your code to make some conflicts for amp and mobile theme.
If I understand correctly you try to set this option and set the code here -> https://www.screencast.com/t/Ks8s2uSflq if this was not working that mean your coed is not longer compatible with amp version.

Thank you for your understanding!

Post count: 22

I set the code in the “ANALYTICS/JS CODES” section in the main section as explained above. The code is being converted to amp code without success which is what causes the errors. How do I stop this code being converted on amp pages?

Post count: 35449

Hi,

The only way to show in amp that code is if that code can be converted to amp.
Please check this articles:
Introduction to advertising on AMP -> https://www.ampproject.org/docs/ads/introduction_ads
Add Analytics to AMP pages -> https://developers.google.com/analytics/devguides/collection/amp-analytics/

Thank you!

Viewing 6 posts - 1 through 6 (of 6 total)
The forum ‘Newspaper’ is closed to new topics and replies.