Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Disabe New Relic for AMP pages?

wordpress

#1

New Relic PHP extension adds inline script tags on webpages. That’s invalid for AMP pages.

How can I disable New Relic only for webpages with URL ending with “/amp”.

Please help. Thanks.


#2

Hi @narayanprusty

When the PHP code that builds the AMP page is called, ensure you call

newrelic_disable_autorum ( );

This function will tell our agent not to inject the inline tags. This should solve your problem :slight_smile:


#3

We also now have a general doc on this: https://docs.newrelic.com/docs/browser/new-relic-browser/troubleshooting/google-amp-validator-fails-due-3rd-party-script


#4

Hi there, I’m Jeff Martens and I serve as the Product Manager for New Relic’s Real User Monitoring product, New Relic Browser. We are seeing more use of AMP and as @clangosch pointed out, we now have a page in our docs dedicated to AMP compatibility. The great thing is that you can disable New Relic real user monitoring just for your AMP pages, keeping it on all your standard pages.

We are also looking into how we can make using AMP more seamless for New Relic APM/Browser users, as well as how we might integrate with the Analytics component of the AMP specs. Stay tuned!

In the meantime, let us know if you have any questions or suggestions!


#5

Hey guys,

I’m hosting on AWS via Cloudways and they have a push button enablement for clients who want to use New Relic on Wordpress sites. And here I am, basically new to New Relic’s capabilities and AMP pages.

After looking at the documents I need a little clearer direction as to where to integrate the code. I started with this doc, which led me to this doc, which lead me to this doc…where do I begin!? I’m not a Tier 3 code developer and just want to disable the Java function in my AMP pages, do I need to create a new directory within an extension file, or I noticed I have a file on my server called NewRelicHandler.php. Can I just edit that file?

Any advice as to where, more specifically how I should proceed to point to the specific AMP pages?

Anything would be greatly appreciated!!

Thanks in advance!

-Chad B.


#6

Hi Chad,

Cloudways has pretty detailed information about getting set up with New Relic. Step4 has suggestions for viewing your New Relic dashboard and determining the Cloudways names for your applications.

Based on your email address (assuming it is the same as that used for Cloudways) it looks like you may have data appearing here.


#7

On our site we use w3tc for caching pages with the enabled plugin new relic for monitoring and the AMP plugin for creating AMP pages.
We have a problem with the work of new relic + w3tc on AMP page
To the code of AMP page the NREUM script is added, but such pages are not valid.
We have used the recommendations that we found in the documentation of New Relic: https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-rum-disable
We have also used the functions newrelic_disable_autorum() and newrelic_ignore_transaction();
We added them to the plugin code amp/amp.php, to wordpress-hook init(), action amp_post_template_data(), we tried to use the plugin Disabled NewRelic For AMP -> https://tah.wordpress.org/plugins/disabled-newrelic-for-amp/developers/

All it works only for the logged in users, if you use incognito session, on the AMP page there is always NREUM script. On the W3TC plugin settings page we gave not found any options that are responsible for adding this script. How can we get rid of this code on AMP pages for all users?


#8

Hi @bwsua.kis - Is it possible to edit the newrelic.ini file? If so, it is possible to disable autorum by setting newrelic.browser_monitoring.auto_instrument=false. More on this can be found at https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-configuration#inivar-autorum.


#9

Thank you for your reply, but we didn’t manage to use your advice because W3TC support team provided us with a solution.
They sent us 2 files that we replaced in the plugin and eveything started working correctly. In file Extension_Amp_Plugin.php the following changes were made:


In file Extension_NewRelic_Plugin.php the following changes were made:

&

Wordpress - V. 4.7.1, W3TC - V. 0.9.5.2

All modified code
Extension_Amp_Plugin.php

add_filter( 'w3tc_newrelic_should_disable_auto_rum',
    array( $this, 'w3tc_newrelic_should_disable_auto_rum' ) );

public function w3tc_newrelic_should_disable_auto_rum( $reject_reason ) {
    $is_amp_endpoint = $this->is_amp_endpoint();
    if ( !is_null( $is_amp_endpoint ) && $is_amp_endpoint ) {
        return 'AMP endpoint';
    }
    return $reject_reason;
}

Extension_NewRelic_Plugin.php

if ( isset( $app['loader_script'] ) && !$this->_should_disable_auto_rum() )

$reject_reason = apply_filters( 'w3tc_newrelic_should_disable_auto_rum', null );
if ( !empty( $reject_reason ) ) {
    $this->newrelic_reject_reason = __( 'rejected by filter: ', 'w3-total-cache' ) . $reject_reason;
    return true;
}

$current_user = wp_get_current_user();

#10

Hi @bwsua.kis - Thanks for the update and the solution that the W3TC team provided.


#11

So good news is w3t actually added this to the plugin. You just have to have amp and new relic extensions active. However, since I have Disqus comments on amp it was still loading. I am disabling Disqus for the time being till we hear back a solution. If anyone has a solution here I would be very happy to help!