Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent New Relic script from being injected in AMP responses #932

Merged
merged 1 commit into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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