{"id":101,"date":"2018-07-20T04:54:00","date_gmt":"2018-07-20T04:54:00","guid":{"rendered":"http:\/\/www.projectimmerse.com\/?p=101"},"modified":"2020-06-17T01:17:45","modified_gmt":"2020-06-17T01:17:45","slug":"wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection","status":"publish","type":"post","link":"https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/","title":{"rendered":"WordPress AMP Plugin Errors due to New Relic Javascript Injection"},"content":{"rendered":"<p>I was working on a high profile website under a big name and they had me implement the AMP plugin a couple months ago. <\/p>\n<p>Pages were working great on mobile thanks to the <a href=\"https:\/\/wordpress.org\/plugins\/accelerated-mobile-pages\/\" title=\"Wordpress AMP Plugin\">WordPress AMP Plugin<\/a>. Then after three months that&#8217;s when a bunch of errors started showing up on the <a href=\"\" title=\"https:\/\/search.google.com\/test\/amp\">Google AMP console<\/a> and I later learned that these errors were very common. <\/p>\n<p><!--more--><\/p>\n<p>But there was one particular error that got me stumped for a while. It was the &#8220;User Authored Javascript Found on Page&#8221; error. AMP doesn&#8217;t like foreign looking Javascript like that, so it was acting up and spitting out an error &#8211; that&#8217;s all that was.<\/p>\n<p>I was curious about what piece of javascript was causing that though. I went for a journey through the source code and found that the javascript was injected by the <a href=\"https:\/\/newrelic.com\/\" title=\"New Relic\">New Relic<\/a> API. This particular site does make use of a spectrum of technologies and infrastructure &#8211; so it totally made sense. But back to the task at hand &#8211; let&#8217;s get that javascript out and move on with our lives.<\/p>\n<p>You want to put the below snippet of code in your functions.php theme file.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/Remove new relic from amp pages\r\nif (function_exists('newrelic_disable_autorum')) {\r\n    add_action('init', function() {\r\n        $url = $_SERVER&#x5B;'REQUEST_URI'];\r\n        if(strpos($url, '\/amp\/') !== false){   \r\n            newrelic_disable_autorum();\r\n        }\r\n    });\r\n};\r\n<\/pre>\n<p>The important part here actually is first checking to see if the new relic function exists then run the following action. Otherwise you will run into additional errors if let&#8217;s say the New Relic was removed entirely from the site &#8211; this would still run and you would be shooting darts in the dark again. <\/p>\n<p>Basically were checking to see &#8216;\/amp\/&#8217; is detected in a URL &#8211; if so, then disable the javascript injected by New Relic. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was working on a high profile website under a big name and they had me implement the AMP plugin a couple months ago. Pages were working great on mobile thanks to the WordPress AMP Plugin. Then after three months that&#8217;s when a bunch of errors started showing up on the Google AMP console and &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;WordPress AMP Plugin Errors due to New Relic Javascript Injection&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":1124,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-101","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Wordpress AMP Plugin Errors due to New Relic Javascript Injection - Project Immerse<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Wordpress AMP Plugin Errors due to New Relic Javascript Injection - Project Immerse\" \/>\n<meta property=\"og:description\" content=\"I was working on a high profile website under a big name and they had me implement the AMP plugin a couple months ago. Pages were working great on mobile thanks to the WordPress AMP Plugin. Then after three months that&#8217;s when a bunch of errors started showing up on the Google AMP console and &hellip; Continue reading &quot;WordPress AMP Plugin Errors due to New Relic Javascript Injection&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/\" \/>\n<meta property=\"og:site_name\" content=\"Project Immerse\" \/>\n<meta property=\"article:published_time\" content=\"2018-07-20T04:54:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-06-17T01:17:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/amp-plugin-errors-new-relic-script-injection-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"750\" \/>\n\t<meta property=\"og:image:height\" content=\"750\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"projectimmerse\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"projectimmerse\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\\\/\"},\"author\":{\"name\":\"projectimmerse\",\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/#\\\/schema\\\/person\\\/c53f2864be524ee6fa08a7e4800dd1e5\"},\"headline\":\"WordPress AMP Plugin Errors due to New Relic Javascript Injection\",\"datePublished\":\"2018-07-20T04:54:00+00:00\",\"dateModified\":\"2020-06-17T01:17:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\\\/\"},\"wordCount\":318,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/07\\\/amp-plugin-errors-new-relic-script-injection-1.png\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\\\/\",\"url\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\\\/\",\"name\":\"Wordpress AMP Plugin Errors due to New Relic Javascript Injection - Project Immerse\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/07\\\/amp-plugin-errors-new-relic-script-injection-1.png\",\"datePublished\":\"2018-07-20T04:54:00+00:00\",\"dateModified\":\"2020-06-17T01:17:45+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/#\\\/schema\\\/person\\\/c53f2864be524ee6fa08a7e4800dd1e5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/07\\\/amp-plugin-errors-new-relic-script-injection-1.png\",\"contentUrl\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/07\\\/amp-plugin-errors-new-relic-script-injection-1.png\",\"width\":750,\"height\":750,\"caption\":\"Wordpress AMP Plugin Errors due to New Relic Javascript Injection\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WordPress AMP Plugin Errors due to New Relic Javascript Injection\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/\",\"name\":\"Project Immerse\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/#\\\/schema\\\/person\\\/c53f2864be524ee6fa08a7e4800dd1e5\",\"name\":\"projectimmerse\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d06955033d6227bfdcf30014e457e4334f7deeb73907de49b65ec2484921931?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d06955033d6227bfdcf30014e457e4334f7deeb73907de49b65ec2484921931?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d06955033d6227bfdcf30014e457e4334f7deeb73907de49b65ec2484921931?s=96&d=mm&r=g\",\"caption\":\"projectimmerse\"},\"url\":\"https:\\\/\\\/www.projectimmerse.com\\\/blog\\\/author\\\/projectimmerse\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Wordpress AMP Plugin Errors due to New Relic Javascript Injection - Project Immerse","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/","og_locale":"en_US","og_type":"article","og_title":"Wordpress AMP Plugin Errors due to New Relic Javascript Injection - Project Immerse","og_description":"I was working on a high profile website under a big name and they had me implement the AMP plugin a couple months ago. Pages were working great on mobile thanks to the WordPress AMP Plugin. Then after three months that&#8217;s when a bunch of errors started showing up on the Google AMP console and &hellip; Continue reading \"WordPress AMP Plugin Errors due to New Relic Javascript Injection\"","og_url":"https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/","og_site_name":"Project Immerse","article_published_time":"2018-07-20T04:54:00+00:00","article_modified_time":"2020-06-17T01:17:45+00:00","og_image":[{"width":750,"height":750,"url":"https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/amp-plugin-errors-new-relic-script-injection-1.png","type":"image\/png"}],"author":"projectimmerse","twitter_card":"summary_large_image","twitter_misc":{"Written by":"projectimmerse","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/#article","isPartOf":{"@id":"https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/"},"author":{"name":"projectimmerse","@id":"https:\/\/www.projectimmerse.com\/blog\/#\/schema\/person\/c53f2864be524ee6fa08a7e4800dd1e5"},"headline":"WordPress AMP Plugin Errors due to New Relic Javascript Injection","datePublished":"2018-07-20T04:54:00+00:00","dateModified":"2020-06-17T01:17:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/"},"wordCount":318,"commentCount":0,"image":{"@id":"https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/#primaryimage"},"thumbnailUrl":"https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/amp-plugin-errors-new-relic-script-injection-1.png","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/","url":"https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/","name":"Wordpress AMP Plugin Errors due to New Relic Javascript Injection - Project Immerse","isPartOf":{"@id":"https:\/\/www.projectimmerse.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/#primaryimage"},"image":{"@id":"https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/#primaryimage"},"thumbnailUrl":"https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/amp-plugin-errors-new-relic-script-injection-1.png","datePublished":"2018-07-20T04:54:00+00:00","dateModified":"2020-06-17T01:17:45+00:00","author":{"@id":"https:\/\/www.projectimmerse.com\/blog\/#\/schema\/person\/c53f2864be524ee6fa08a7e4800dd1e5"},"breadcrumb":{"@id":"https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/#primaryimage","url":"https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/amp-plugin-errors-new-relic-script-injection-1.png","contentUrl":"https:\/\/www.projectimmerse.com\/blog\/wp-content\/uploads\/2018\/07\/amp-plugin-errors-new-relic-script-injection-1.png","width":750,"height":750,"caption":"Wordpress AMP Plugin Errors due to New Relic Javascript Injection"},{"@type":"BreadcrumbList","@id":"https:\/\/www.projectimmerse.com\/blog\/wordpress-amp-plugin-errors-due-to-new-relic-javascript-injection\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.projectimmerse.com\/blog\/"},{"@type":"ListItem","position":2,"name":"WordPress AMP Plugin Errors due to New Relic Javascript Injection"}]},{"@type":"WebSite","@id":"https:\/\/www.projectimmerse.com\/blog\/#website","url":"https:\/\/www.projectimmerse.com\/blog\/","name":"Project Immerse","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.projectimmerse.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.projectimmerse.com\/blog\/#\/schema\/person\/c53f2864be524ee6fa08a7e4800dd1e5","name":"projectimmerse","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4d06955033d6227bfdcf30014e457e4334f7deeb73907de49b65ec2484921931?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4d06955033d6227bfdcf30014e457e4334f7deeb73907de49b65ec2484921931?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d06955033d6227bfdcf30014e457e4334f7deeb73907de49b65ec2484921931?s=96&d=mm&r=g","caption":"projectimmerse"},"url":"https:\/\/www.projectimmerse.com\/blog\/author\/projectimmerse\/"}]}},"_links":{"self":[{"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/posts\/101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/comments?post=101"}],"version-history":[{"count":2,"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/posts\/101\/revisions"}],"predecessor-version":[{"id":465,"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/posts\/101\/revisions\/465"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/media\/1124"}],"wp:attachment":[{"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/media?parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/categories?post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.projectimmerse.com\/blog\/wp-json\/wp\/v2\/tags?post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}