Skip to content

Commit

Permalink
Only track product page marketplace suggestions when visible.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffstieler committed Apr 9, 2019
1 parent 0061a21 commit 742b3d6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
36 changes: 28 additions & 8 deletions assets/js/admin/marketplace-suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@
} );
}

// track the current product data tab to avoid over-tracking suggestions
var currentTab = false;

// Render suggestion data in appropriate places in UI.
function displaySuggestions( marketplaceSuggestionsApiData ) {
var usedSuggestionsContexts = [];
Expand Down Expand Up @@ -365,15 +368,26 @@
$( this ).append( content );
$( this ).addClass( 'showing-suggestion' );
usedSuggestionsContexts.push( context );

window.wcTracks.recordEvent( 'marketplace_suggestion_displayed', {
suggestion_slug: suggestionsToDisplay[ i ].slug,
context: context,
product: suggestionsToDisplay[ i ].product || '',
promoted: suggestionsToDisplay[ i ].promoted || '',
target: suggestionsToDisplay[ i ].url || ''
} );
}

// track when suggestions are displayed (and not already visible)
$( 'ul.product_data_tabs li.marketplace-suggestions_options a' ).click( function( e ) {
e.preventDefault();

if ( '#marketplace_suggestions' === currentTab ) {
return;
}

for ( var i in suggestionsToDisplay ) {
window.wcTracks.recordEvent( 'marketplace_suggestion_displayed', {
suggestion_slug: suggestionsToDisplay[ i ].slug,
context: context,
product: suggestionsToDisplay[ i ].product || '',
promoted: suggestionsToDisplay[ i ].promoted || '',
target: suggestionsToDisplay[ i ].url || ''
} );
}
} );
} );

hidePageElementsForSuggestionState( usedSuggestionsContexts );
Expand All @@ -382,6 +396,12 @@

if ( marketplace_suggestions.suggestions_data ) {
displaySuggestions( marketplace_suggestions.suggestions_data );

// track the current product data tab to avoid over-reporting suggestion views
$( 'ul.product_data_tabs' ).on( 'click', 'li a', function( e ) {
e.preventDefault();
currentTab = $( this ).attr( 'href' );
} );
}

addManageSuggestionsTracksHandler();
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin/marketplace-suggestions.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 742b3d6

Please sign in to comment.