Skip to content

Commit

Permalink
add "?amp" instead of "/amp/" for AMP visit tracking (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
stklcode committed Jul 19, 2021
1 parent c49ff94 commit 01458e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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

0 comments on commit 01458e8

Please sign in to comment.