Skip to content

Commit 01458e8

Browse files
committed
add "?amp" instead of "/amp/" for AMP visit tracking (#183)
1 parent c49ff94 commit 01458e8

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

inc/class-statify-frontend.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private static function make_amp_config() {
163163
),
164164
'extraUrlParams' => array(
165165
'referrer' => '${documentReferrer}',
166-
'target' => '${canonicalPath}amp/',
166+
'target' => '${canonicalPath}?amp',
167167
),
168168
'triggers' => array(
169169
'trackPageview' => array(

inc/class-statify.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,15 @@ protected static function track( $referrer, $target ) {
135135
/* Global vars */
136136
global $wp_rewrite;
137137

138-
// Trim target URL.
138+
// Trim target URL, i.e. remove query parameters..
139139
if ( $wp_rewrite->permalink_structure ) {
140-
$target = wp_parse_url( $target, PHP_URL_PATH );
140+
$parsed_target = wp_parse_url( $target );
141+
$target = isset( $parsed_target['path'] ) ? $parsed_target['path'] : null;
142+
143+
// Re-add AMP parameter to preserve that information (only applicable for JS tracking).
144+
if ( isset( $parsed_target['query'] ) && 'amp/' === $parsed_target['query'] ) {
145+
add_query_arg( 'amp', '', $target );
146+
}
141147
}
142148

143149
// Init rows.

0 commit comments

Comments
 (0)