Skip to content

Commit

Permalink
Merge pull request #932 from Automattic/fix/newrelic
Browse files Browse the repository at this point in the history
Prevent New Relic script from being injected in AMP responses
  • Loading branch information
westonruter committed Feb 5, 2018
2 parents c293486 + 2cab5bb commit 7b88ae0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ function amp_render_post( $post ) {
$wp_query->query_vars[ AMP_QUERY_VAR ] = true;
}

// Prevent New Relic from causing invalid AMP responses due the NREUM script it injects after the meta charset.
if ( extension_loaded( 'newrelic' ) ) {
newrelic_disable_autorum();
}

/**
* Fires before rendering a post in AMP.
*
Expand Down
11 changes: 11 additions & 0 deletions includes/class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,17 @@ protected static function ensure_required_markup( DOMDocument $dom ) {
* @see AMP_Theme_Support::finish_output_buffering()
*/
public static function start_output_buffering() {
/*
* Disable the New Relic Browser agent on AMP responses.
* This prevents th New Relic from causing invalid AMP responses due the NREUM script it injects after the meta charset:
* https://docs.newrelic.com/docs/browser/new-relic-browser/troubleshooting/google-amp-validator-fails-due-3rd-party-script
* Sites with New Relic will need to specially configure New Relic for AMP:
* https://docs.newrelic.com/docs/browser/new-relic-browser/installation/monitor-amp-pages-new-relic-browser
*/
if ( extension_loaded( 'newrelic' ) ) {
newrelic_disable_autorum();
}

ob_start();

// Note that the following must be at 0 because wp_ob_end_flush_all() runs at shutdown:1.
Expand Down

0 comments on commit 7b88ae0

Please sign in to comment.