Merge pull request #23253 from woocommerce/fix/edit-product-marketplace-suggestion-tracking

[3.6] Only track product page marketplace suggestions when visible.
This commit is contained in:
Timmy Crawford 2019-04-09 09:53:03 -07:00 committed by GitHub
commit 7d1a023cf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 9 deletions

View File

@ -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. // Render suggestion data in appropriate places in UI.
function displaySuggestions( marketplaceSuggestionsApiData ) { function displaySuggestions( marketplaceSuggestionsApiData ) {
var usedSuggestionsContexts = []; var usedSuggestionsContexts = [];
@ -365,7 +368,17 @@
$( this ).append( content ); $( this ).append( content );
$( this ).addClass( 'showing-suggestion' ); $( this ).addClass( 'showing-suggestion' );
usedSuggestionsContexts.push( context ); usedSuggestionsContexts.push( context );
}
// 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', { window.wcTracks.recordEvent( 'marketplace_suggestion_displayed', {
suggestion_slug: suggestionsToDisplay[ i ].slug, suggestion_slug: suggestionsToDisplay[ i ].slug,
context: context, context: context,
@ -375,6 +388,7 @@
} ); } );
} }
} ); } );
} );
hidePageElementsForSuggestionState( usedSuggestionsContexts ); hidePageElementsForSuggestionState( usedSuggestionsContexts );
tidyProductEditMetabox(); tidyProductEditMetabox();
@ -382,6 +396,12 @@
if ( marketplace_suggestions.suggestions_data ) { if ( marketplace_suggestions.suggestions_data ) {
displaySuggestions( 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(); addManageSuggestionsTracksHandler();

File diff suppressed because one or more lines are too long