Skip to content

Commit

Permalink
First pass at tracking individual image hits when full-screen, in Car…
Browse files Browse the repository at this point in the history
…ousel
  • Loading branch information
elliott-stocks committed Apr 7, 2016
1 parent 8d13e90 commit 4b70301
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions modules/carousel/jetpack-carousel.js
Expand Up @@ -692,6 +692,14 @@ jQuery(document).ready(function($) {
caption.fadeOut( 'fast' ).empty();
}

// Record pageview in WP Stats, for each new image loaded full-screen.
if ( jetpackCarouselStrings.stats ) {
new Image().src = document.location.protocol +
'//pixel.wp.com/g.gif?' +
jetpackCarouselStrings.stats +
'&post=' + encodeURIComponent( attachmentId ) +
'&rand=' + Math.random();
}

// Load the images for the next and previous slides.
$( next ).add( previous ).each( function() {
Expand Down
18 changes: 18 additions & 0 deletions modules/carousel/jetpack-carousel.php
Expand Up @@ -211,6 +211,24 @@ function enqueue_assets( $output ) {
}
}

/**
* Handle WP stats for images in full-screen.
* Build string with tracking info.
*/
if ( ! in_array( 'stats', Jetpack::get_active_modules() ) ) {
$localize_strings['stats'] = 'blog=' . Jetpack_Options::get_option( 'id' ) . '&host=' . parse_url( get_option( 'home' ), PHP_URL_HOST ) . '&v=ext&j=' . JETPACK__API_VERSION . ':' . JETPACK__VERSION;

// Set the stats as empty if user is logged in but logged-in users shouldn't be tracked.
if ( is_user_logged_in() && function_exists( 'stats_get_options' ) ) {
$stats_options = stats_get_options();
$track_loggedin_users = isset( $stats_options['reg_users'] ) ? (bool) $stats_options['reg_users'] : false;

if ( ! $track_loggedin_users ) {
$localize_strings['stats'] = '';
}
}
}

/**
* Filter the strings passed to the Carousel's js file.
*
Expand Down

0 comments on commit 4b70301

Please sign in to comment.