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

add "?amp" instead of "/amp/" for AMP visit tracking (#183) #195

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion inc/class-statify-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private static function make_amp_config() {
),
'extraUrlParams' => array(
'referrer' => '${documentReferrer}',
'target' => '${canonicalPath}amp/',
'target' => '${canonicalPath}?amp',
),
'triggers' => array(
'trackPageview' => array(
Expand Down
10 changes: 8 additions & 2 deletions inc/class-statify.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,15 @@ protected static function track( $referrer, $target ) {
/* Global vars */
global $wp_rewrite;

// Trim target URL.
// Trim target URL, i.e. remove query parameters..
if ( $wp_rewrite->permalink_structure ) {
$target = wp_parse_url( $target, PHP_URL_PATH );
$parsed_target = wp_parse_url( $target );
$target = isset( $parsed_target['path'] ) ? $parsed_target['path'] : null;

// Re-add AMP parameter to preserve that information (only applicable for JS tracking).
if ( isset( $parsed_target['query'] ) && 'amp/' === $parsed_target['query'] ) {
add_query_arg( 'amp', '', $target );
}
}

// Init rows.
Expand Down