put products list suggestions on hiatus (month) if user dismisses 5:

- track the number of dismissals of products list suggestions in a cookie
- if this exceeds 5, don't show any product list suggestions
- set that cookie to expire in one month – suggestions will resume then
This commit is contained in:
haszari 2019-03-08 13:11:00 +13:00
parent d575bf5013
commit 8704a32302
2 changed files with 20 additions and 3 deletions

View File

@ -38,7 +38,14 @@
// if this is a high-use area, delay new suggestion that area for a short while // if this is a high-use area, delay new suggestion that area for a short while
var highUseSuggestionContexts = [ 'products-list-inline' ]; var highUseSuggestionContexts = [ 'products-list-inline' ];
if ( _.contains( highUseSuggestionContexts, context ) ) { if ( _.contains( highUseSuggestionContexts, context ) ) {
Cookies.set( 'woocommerce_snooze_products_list_suggestions', '1', { expires: 2 } ); // snooze suggestions in that area for 2 days
var contextSnoozeCookie = 'woocommerce_snooze_suggestions__' + context;
Cookies.set( contextSnoozeCookie, 'true', { expires: 2 } );
// keep track of how often this area gets dismissed in a cookie
var contextDismissalCountCookie = 'woocommerce_dismissed_suggestions__' + context;
var previousDismissalsInThisContext = parseInt( Cookies.get( contextDismissalCountCookie ) ) || 0;
Cookies.set( contextDismissalCountCookie, previousDismissalsInThisContext + 1, { expires: 31 } );
} }
window.wcTracks.recordEvent( 'marketplace_suggestion_dismissed', { window.wcTracks.recordEvent( 'marketplace_suggestion_dismissed', {
@ -374,10 +381,20 @@
var context = 'products-list-inline'; var context = 'products-list-inline';
// product list banner suggestion is temporarily suppressed after a recent dismissal // product list banner suggestion is temporarily suppressed after a recent dismissal
if ( Cookies.get( 'woocommerce_snooze_products_list_suggestions' ) ) { var contextSnoozeCookie = 'woocommerce_snooze_suggestions__' + context;
if ( Cookies.get( contextSnoozeCookie ) ) {
return; return;
} }
// product list banner suggestion has been dismissed repeatedly give user a break
// note that this is longer term but still temporary, based on the expiry of the cookie
var hideSuggestionsDismissalThreshold = 5;
var contextDismissalCountCookie = 'woocommerce_dismissed_suggestions__' + context;
if ( parseInt( Cookies.get( 'contextDismissalCountCookie' ) ) > hideSuggestionsDismissalThreshold ) {
return;
}
// find promotions that target this context // find promotions that target this context
var promos = getRelevantPromotions( marketplaceSuggestionsApiData, context ); var promos = getRelevantPromotions( marketplaceSuggestionsApiData, context );
if ( ! promos || ! promos.length ) { if ( ! promos || ! promos.length ) {

File diff suppressed because one or more lines are too long