Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
hide B2C messaging from B2B prospects
Browse files Browse the repository at this point in the history
* hide Lionel
* hide B2C marketing promo
* TODO: test coverage for promoHandler.js
  • Loading branch information
doramatadora committed May 15, 2017
1 parent ccb6205 commit aab97df
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 40 deletions.
57 changes: 35 additions & 22 deletions components/n-ui/header/js/promoHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Update flags and next-product selector accordingly

import { products } from 'next-session-client';
import Superstore from 'superstore';

const discount = {
L: 50,
Expand Down Expand Up @@ -37,6 +38,13 @@ function isBarrier () {
return !!document.querySelector('.barrier');
}

function isB2BProspect () {
const sessionStore = new Superstore('session', 'next.product-selector');
return sessionStore.get('barrier-messaging')
.then(barrier => barrier === 'B2B')
.catch(() => false)
}

function showPromo (flags) {
const promo = document.querySelector('.n-header__marketing-promo');

Expand Down Expand Up @@ -95,32 +103,37 @@ function showElectionsOffer (flags) {
* We want to hide the marketing promo from:
* - Signup form
* - Barriers
* - B2B prospects
*/
export function init (flags) {

// If it's the signup form or a barrier, just stop
if (!isSignupForm() && !isBarrier()) {

// If it's a CORS-compatible browser, fetch the session
if (supportsCors()) {
getUserProducts()
.then(decorateTheSession)
.then(function (session) {
if (session.isForAnonymousUser || session.isForRegisteredUser || session.isForWeekendUser) {

if (showElectionsOffer(flags)) {
showElectionPromo()
} else {
showPromo(flags);
}

}
});
}
else if (checkAnonWithoutSession()) {
// If can't do cors but anonymous, just show the promo
// Pending cors solution
showPromo(flags);
}
// If the last barrier shown was B2B, just stop
isB2BProspect().then(isB2B => {
if(!isB2B){
// If it's a CORS-compatible browser, fetch the session
if (supportsCors()) {
getUserProducts()
.then(decorateTheSession)
.then(function (session) {
if (session.isForAnonymousUser || session.isForRegisteredUser || session.isForWeekendUser) {

if (showElectionsOffer(flags)) {
showElectionPromo()
} else {
showPromo(flags);
}

}
});
}
else if (checkAnonWithoutSession()) {
// If can't do cors but anonymous, just show the promo
// Pending cors solution
showPromo(flags);
}
}
});
}
}
19 changes: 8 additions & 11 deletions components/n-ui/subscription-offer-prompt/lionel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,25 @@ import { broadcast } from 'n-ui-foundations';

const promptLastSeenStorage = new Superstore('local', 'n-ui.subscription-offer-prompt');
const promptLastSeenStorageKey = 'last-closed';

const getProductSelectorLastSeen = () => {
const sessionStore = new Superstore('session', 'next.product-selector');
return sessionStore.get('last-seen')
.catch(() => null)
};

const getPromptLastClosed = () => promptLastSeenStorage.get(promptLastSeenStorageKey);

const setPromptLastClosed = () => promptLastSeenStorage.set(promptLastSeenStorageKey, Date.now());

const productSelectorStorage = new Superstore('session', 'next.product-selector');
const getBarrierLastSeen = () => productSelectorStorage.get('last-seen');
const getBarrierMessaging = () => productSelectorStorage.get('barrier-messaging');

/**
* Show the prompt if
* * not logged in
* * not on a barrier page
* * the barrier has been seen in this session
* * the last barrier shown did not have B2B messaging
* * the prompt has not been closed, or was last closed more than 30 days ago
*/
const shouldPromptBeShown = () => {
return Promise.all([getProductSelectorLastSeen(), getPromptLastClosed()])
.then(([barrierLastSeen, promptLastClosed]) =>
barrierLastSeen && (!promptLastClosed || promptLastClosed + (1000 * 60 * 60 * 24 * 30) <= Date.now())
return Promise.all([getBarrierLastSeen(), getBarrierMessaging(), getPromptLastClosed()])
.then(([barrierLastSeen, barrierMessaging, promptLastClosed]) =>
barrierLastSeen && barrierMessaging !=='B2B' && (!promptLastClosed || promptLastClosed + (1000 * 60 * 60 * 24 * 30) <= Date.now())
);
};

Expand Down
25 changes: 18 additions & 7 deletions components/n-ui/subscription-offer-prompt/test/lionel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ describe('"Lionel Slider" Subscription Offer Prompt', () => {

return Promise.all([
localStorage.set('last-closed', Date.now() - (1000 * 60 * 60 * 24 * 30)),
sessionStorage.set('last-seen', Date.now())
sessionStorage.set('last-seen', Date.now()),
sessionStorage.set('barrier-messaging', 'B2C')
])
});

Expand All @@ -33,7 +34,8 @@ describe('"Lionel Slider" Subscription Offer Prompt', () => {
// fixme - the tests fail in IE11 if these are not commented out. I have no idea why..
return Promise.all([
// localStorage.unset('last-closed'),
// sessionStorage.unset('last-seen')
// sessionStorage.unset('last-seen'),
// sessionStorage.unset('barrier-messaging')
]);
});

Expand Down Expand Up @@ -103,11 +105,16 @@ describe('"Lionel Slider" Subscription Offer Prompt', () => {
return init(flags).then(popup => should.not.exist(popup));
});

it('should not show barrier page has not been visited in this session', () => {
it('should not show if barrier page has not been visited in this session', () => {
sessionStorage.unset('last-seen');
return init(flags).then(popup => should.not.exist(popup));
});

it('should not show in succession to a B2B barrier', () => {
sessionStorage.set('barrier-messaging', 'B2B')
return init(flags).then(popup => should.not.exist(popup));
});

});

describe('"Lionel Slider" Subscription Offer Prompt - USA', () => {
Expand All @@ -128,7 +135,8 @@ describe('"Lionel Slider" Subscription Offer Prompt - USA', () => {

return Promise.all([
localStorage.set('last-closed', Date.now() - (1000 * 60 * 60 * 24 * 30)),
sessionStorage.set('last-seen', Date.now())
sessionStorage.set('last-seen', Date.now()),
sessionStorage.set('barrier-messaging', 'B2C')
])
});

Expand All @@ -138,7 +146,8 @@ describe('"Lionel Slider" Subscription Offer Prompt - USA', () => {
// fixme - the tests fail in IE11 if these are not commented out. I have no idea why..
return Promise.all([
// localStorage.unset('last-closed'),
// sessionStorage.unset('last-seen')
// sessionStorage.unset('last-seen'),
// sessionStorage.unset('barrier-messaging')
]);
});

Expand Down Expand Up @@ -176,7 +185,8 @@ describe('"Lionel Slider" Subscription Offer Prompt - country code not listed',

return Promise.all([
localStorage.set('last-closed', Date.now() - (1000 * 60 * 60 * 24 * 30)),
sessionStorage.set('last-seen', Date.now())
sessionStorage.set('last-seen', Date.now()),
sessionStorage.set('barrier-messaging', 'B2C')
])
});

Expand All @@ -186,7 +196,8 @@ describe('"Lionel Slider" Subscription Offer Prompt - country code not listed',
// fixme - the tests fail in IE11 if these are not commented out. I have no idea why..
return Promise.all([
// localStorage.unset('last-closed'),
// sessionStorage.unset('last-seen')
// sessionStorage.unset('last-seen'),
// sessionStorage.unset('barrier-messaging')
]);
});

Expand Down

0 comments on commit aab97df

Please sign in to comment.