Skip to content

Instantly share code, notes, and snippets.

@electricbrick
Created May 7, 2018 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save electricbrick/8ccb8cb7db0b1ddf661f41c2f24d52cc to your computer and use it in GitHub Desktop.
Save electricbrick/8ccb8cb7db0b1ddf661f41c2f24d52cc to your computer and use it in GitHub Desktop.
/**
* Finds all Pardot form iframes and appends a ?embedded_on= query parameter to the source.
* Very useful for fixing the crappy issues with pardot tracking...
*/
add_filter( 'pardot_content', 'pardot_iframe_src_filter', 99, 1 );
function pardot_iframe_src_filter( $content ) {
global $post;
$permalink_path = wp_make_link_relative( get_permalink( $post->ID ) );
$ga = ( isset( $_COOKIE['_ga'] ) && ! empty( $_COOKIE['_ga'] ) ) ? $_COOKIE['_ga'] : null;
$content = preg_replace( '#\<iframe(.*?)\ssrc\=\"http(s)?:\/\/(www2\.alliedtelecom\.net|go\.pardot\.com)(.*?)\"(.*?)\>#i', '<iframe$1 src="https://go.pardot.com$4/?embedded_on=' . urlencode( $permalink_path ) . '&embedPageName=' . urlencode( $post->post_title ) . ( $ga ? '&_ga=' . urlencode( $ga ) : '' ) . '"$5>', $content );
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment