Thank you for the help. The following is what I did and it is working. Note to others: You must replace “example.com” and use your own google analytics ID (UA-xxx…).
The ga(‘create’, may be redundant because it’s probably in your page footer tracking code already. I’m not a Google Analytics expert, so I’m not sure if you need one for each click on a page.
jQuery(document).on( 'jp_carousel.selectSlide', '.jp-carousel-wrap', function( event, slides ) {
// pass value to google analytics
ga('create', 'UA-xxxx-1', 'example.com');
ga('send', 'pageview', { 'page': location.pathname + location.search + location.hash});
} );
That puts the full path including the anchor (#) tag into GA. Something like:
/dir/subdir/pagename/#jp-carousel-1744 — This way you can take a look at your most popular images, trace what people look at next, and even figure out what images they are skipping.
Because I have a child theme (as most trying this will) I needed “get_stylesheet_directory_uri” in the following (a variation from many examples) to enqueue in my theme_functions.php (vantage_child is just the name of my theme). I used the browser console to debug path errors for the missing script.
/**
* enqueue script
*/
function vantage_child_scripts() {
wp_enqueue_script( 'carousel-analytics', get_stylesheet_directory_uri() . '/js/carousel-analytics.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'vantage_child_scripts' );