Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-1774/In-App Insights Promo #460

Merged
merged 40 commits into from Oct 24, 2019
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0f49440
Created modal UI
benstrumeyer Sep 26, 2019
5f92023
Change feature language. Add exit button.
benstrumeyer Sep 27, 2019
b229c9d
Add insights modal that will appear if a user clicks 3x per day for 3…
benstrumeyer Oct 8, 2019
3d24d70
Refactor insights modal into a component. Reshow modal after prompted…
benstrumeyer Oct 8, 2019
d57c5b3
Clean up insights modal code
benstrumeyer Oct 9, 2019
2f7fcbc
Show plus promo modal on first view of Home view of each Hub session
wlycdgr Sep 16, 2019
e94a749
Stub out intro hub plus promo modal layout and implement its buttons
wlycdgr Sep 16, 2019
894d742
Remove some unnecessary plus promo modal related CSS
wlycdgr Sep 17, 2019
ab4c58a
Continue adding styling for plus promo modal
wlycdgr Sep 17, 2019
3cd79ce
Continue styling plus promo modal
wlycdgr Sep 18, 2019
b476ce1
Refactor plus promo modal CSS to improve alignment of elements
wlycdgr Sep 20, 2019
4666877
Continue CSS work for plus promo modal
wlycdgr Sep 20, 2019
ff4d455
Implement recommended gold banner in plus promo modal
wlycdgr Sep 23, 2019
446d137
Update and tweak plus promo modal design
wlycdgr Sep 27, 2019
5afd2ce
Fix path bug in i18n-checker tool. Consolidate redundant entries in m…
wlycdgr Oct 1, 2019
475143c
Additional consolidation of redundant and unused entries in messages
wlycdgr Oct 2, 2019
2f912b7
Factor plus promo modal rendering out to shared component. Implement …
wlycdgr Oct 6, 2019
6e7be93
Move Plus Promo modal rendering to a PlusPromoModal shared component.…
wlycdgr Oct 7, 2019
41a08b1
Create ModalPromos background class responsible for modal promo relat…
wlycdgr Oct 7, 2019
75fa2da
Add local state to Panel to make sure component rerenders after user …
wlycdgr Oct 8, 2019
4329146
Make PromoModals code more robust
wlycdgr Oct 8, 2019
66c1490
Factor PlusPromoModal rendering out to helper in Panel. Extend condit…
wlycdgr Oct 8, 2019
bb5d74d
Mark PromoModals methods as static. Refine PlusPromoModal implementat…
wlycdgr Oct 8, 2019
dd808b5
Add logic to hide plus promo modal from Insights subscribers. Cleanup…
wlycdgr Oct 9, 2019
a143c18
Clean up. Finish string localization in PlusPromoModal
wlycdgr Oct 9, 2019
3795b25
Plug in insights modal into promo modal class
benstrumeyer Oct 16, 2019
cd467c8
GH-1777 and GH-1776 Plus Promo modals (#458)
wlycdgr Oct 16, 2019
178ebf0
Consolidate insights promo with plus promo
benstrumeyer Oct 18, 2019
4b7b84a
GH-1814/promo toggle (#453)
benstrumeyer Oct 18, 2019
7fb7744
User can opt out of promotions
benstrumeyer Oct 18, 2019
3697774
Remove empty SCSS class
benstrumeyer Oct 18, 2019
2abb7cd
Add newlines
benstrumeyer Oct 18, 2019
be57477
Merge 8.4.5
benstrumeyer Oct 18, 2019
b0aa51b
Add hover effects
benstrumeyer Oct 21, 2019
8231933
Refactor insights promo to use redux. Remove summary component code. …
benstrumeyer Oct 23, 2019
3478857
Refactor hasEngagedFrequently to update in recordEngaged
benstrumeyer Oct 23, 2019
b490d7c
Refactor recordEngaged
benstrumeyer Oct 24, 2019
0edc57c
Fix recordEngaged bug
benstrumeyer Oct 24, 2019
14936c6
Fix font paths
wlycdgr Oct 24, 2019
1d905aa
Remove unused font asset
wlycdgr Oct 24, 2019
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

Add insights modal that will appear if a user clicks 3x per day for 3…

… days. Users subscribed to insights will not be shown promos.
  • Loading branch information
benstrumeyer committed Oct 18, 2019
commit b229c9da66f5bb5d1fdc08504cecd97ac429d6a2
@@ -12,12 +12,14 @@
*/

import React from 'react';
import { NavLink } from 'react-router-dom';
import Header from '../containers/HeaderContainer';
import { DynamicUIPortContext } from '../contexts/DynamicUIPortContext';
import { sendMessage } from '../utils/msg';
import { setTheme } from '../utils/utils';
import { Modal } from '../../shared-components';
import ModalExitButton from '../../shared-components/ModalExitButton/ModalExitButton';
import { login } from '../../Account/AccountActions';
/**
* @class Implement base view with functionality common to all views.
* @memberof PanelClasses
@@ -26,7 +28,7 @@ class Panel extends React.Component {
constructor(props) {
super(props);
this.state = {
showModal: true
hasEngagedFrequently: true
};

// event bindings
@@ -40,7 +42,6 @@ class Panel extends React.Component {
*/
componentDidMount() {
sendMessage('ping', 'engaged');

this._dynamicUIDataInitialized = false;
this._dynamicUIPort = chrome.runtime.connect({ name: 'dynamicUIPanelPort' });
this._dynamicUIPort.onMessage.addListener((msg) => {
@@ -54,6 +55,15 @@ class Panel extends React.Component {
this.props.actions.updatePanelData(body);
}
});

chrome.runtime.onMessage.addListener((request) => {
if (request.name === 'hasEngagedFrequently') {
this.setState({
...this.state,
hasEngagedFrequently: true
});
}
});
}

/**
@@ -63,75 +73,38 @@ class Panel extends React.Component {
this._dynamicUIPort.disconnect();
}

/**
* Function to handle clicking yes on the Modal
*/
_answerModalYes = () => {
this._toggleModal();
}

/**
* Function to toggle the Modal
*/
_toggleModal = () => {
const { showModal } = this.state;
toggleModal = () => {
const { hasEngagedFrequently } = this.state;
this.setState({
showModal: !showModal,
hasEngagedFrequently: !hasEngagedFrequently
});
}

_renderModalChildren() {
return (
<div className="InsightsModal__content flex-container flex-dir-column align-middle">
<ModalExitButton exitModal={this._toggleModal} className="InsightsModal__exitButton" hrefExit="Test" textExit="" />
<div className="InsightsModal__image" />
<div className="InsightsModal__header">
Try Ghostery Insights
</div>
<div className="InsightsModal__description">
Speed up and clean up digital user experience with our professional tag analytics tool.
</div>
<div className="flex-container">
<div className="flex-container flex-dir-column InsightsModal__feature-column-1">
<div className="flex-container align-middle">
<span className="InsightsModal__checkedCircleIcon" />
<div className="InsightsModal__featureText">
Audit marketing tags on a page
</div>
</div>
<div className="flex-container align-middle">
<span className="InsightsModal__checkedCircleIcon" />
<span className="InsightsModal__featureText">
Trace sources of poor performance
</span>
</div>
</div>
<div className="InsightsModal__feature-column-2 flex-container flex-dir-column">
<div className="flex-container align-middle">
<span className="InsightsModal__checkedCircleIcon" />
<span className="InsightsModal__featureText">
Watch pings fire in real-time
</span>
</div>
<div className="flex-container align-middle">
<span className="InsightsModal__checkedCircleIcon" />
<span className="InsightsModal__featureText">
Explore global digital trends
</span>
</div>
</div>
</div>
<div className="InsightsModal__callToActionContainer flex-container flex-dir-column">
<button type="button" className="btn InsightsModal__callToAction align-self-middle">
<span className="InsightsModal__callToActionText">CTA TEXT</span>
</button>
<div className="InsightsModal__otherOptionsContainer flex-container align-justify">
<a className="InsightsModal__link">Already an Insights subscriber?</a>
<a onClick={this._toggleModal} className="InsightsModal__link">No thanks, maybe later</a>
</div>
</div>
</div>
);
generateModal = () => {
const { loggedIn, user } = this.props;
const { hasEngagedFrequently } = this.state;
if (!loggedIn && hasEngagedFrequently) {
return true;
}
return hasEngagedFrequently && loggedIn && !user.scopes.includes('subscriptions:insights');
}

clickSignIn = () => {
this.props.history.push('/login');
this.setState({ hasEngagedFrequently: false });
}

/**
* Reload the current tab
* @param {Object} event
* @todo Why do we need explicit argument here?
*/
clickReloadBanner() {
sendMessage('reloadTab', { tab_id: +this.props.tab_id });
window.close();
}

/**
@@ -156,16 +129,6 @@ class Panel extends React.Component {
});
}

/**
* Reload the current tab
* @param {Object} event
* @todo Why do we need explicit argument here?
*/
clickReloadBanner() {
sendMessage('reloadTab', { tab_id: +this.props.tab_id });
window.close();
}

/**
* Filter trackers when clicking on compatibility/slow
* tracker notifications and trigger appropriate action.
@@ -187,12 +150,12 @@ class Panel extends React.Component {

this.closeNotification();
}

/**
* Dynamic UI data port first payload handling
* Called once, when we get the first message from the background through the port
* @param {Object} payload the body of the message
*/

_initializeData(payload) {
this._dynamicUIDataInitialized = true;

@@ -270,6 +233,60 @@ class Panel extends React.Component {
return false;
}

renderModalChildren() {
return (
<div className="InsightsModal__content flex-container flex-dir-column align-middle">
<ModalExitButton exitModal={this.toggleModal} className="InsightsModal__exitButton" hrefExit="Test" textExit="" />
<div className="InsightsModal__image" />
<div className="InsightsModal__header">
Try Ghostery Insights
</div>
<div className="InsightsModal__description">
Speed up and clean up digital user experience with our professional tag analytics tool.
</div>
<div className="flex-container">
<div className="flex-container flex-dir-column InsightsModal__feature-column-1">
<div className="flex-container align-middle">
<span className="InsightsModal__checkedCircleIcon" />
<div className="InsightsModal__featureText">
Audit marketing tags on a page
</div>
</div>
<div className="flex-container align-middle">
<span className="InsightsModal__checkedCircleIcon" />
<span className="InsightsModal__featureText">
Trace sources of poor performance
</span>
</div>
</div>
<div className="InsightsModal__feature-column-2 flex-container flex-dir-column">
<div className="flex-container align-middle">
<span className="InsightsModal__checkedCircleIcon" />
<span className="InsightsModal__featureText">
Watch pings fire in real-time
</span>
</div>
<div className="flex-container align-middle">
<span className="InsightsModal__checkedCircleIcon" />
<span className="InsightsModal__featureText">
Explore global digital trends
</span>
</div>
</div>
</div>
<div className="InsightsModal__callToActionContainer flex-container flex-dir-column">
<a href="https://www.ghostery.com/insights/" target="_blank" rel="noopener noreferrer" className="btn InsightsModal__callToAction align-self-middle">
<span className="InsightsModal__callToActionText flex-container align-center">Try for free</span>
</a>
<div className="InsightsModal__otherOptionsContainer flex-container align-justify">
<span onClick={this.clickSignIn} className="InsightsModal__link">Already a subscriber? Sign in</span>
<span onClick={this.toggleModal} className="InsightsModal__link">No thanks, maybe later</span>
</div>
</div>
</div>
);
}

/**
* React's required render function. Returns JSX
* @return {JSX} JSX for rendering the Panel
@@ -280,7 +297,6 @@ class Panel extends React.Component {
return null;
}

const { showModal } = this.state;
const notificationText = this.props.notificationShown && this.renderNotification();

return (
@@ -298,8 +314,8 @@ class Panel extends React.Component {
</div>
</div>
<Header />
<Modal show={showModal}>
{this._renderModalChildren()}
<Modal show={this.generateModal()}>
{this.renderModalChildren()}
</Modal>
<DynamicUIPortContext.Provider value={this._dynamicUIPort}>
{ this.props.children }
@@ -27,10 +27,10 @@ import { updateBlockingData } from '../actions/BlockingActions';
* @todo We are not using ownProps, so we better not specify it explicitly,
* in this case it won't be passed by React (see https://github.com/reactjs/react-redux/blob/master/docs/api.md).
*/
const mapStateToProps = state => Object.assign({}, state.panel, state.drawer, {
const mapStateToProps = state => Object.assign({}, state.panel, state.drawer, state.account, {
paused_blocking: state.summary.paused_blocking,
sitePolicy: state.summary.sitePolicy,
trackerCounts: state.summary.trackerCounts,
trackerCounts: state.summary.trackerCounts
This conversation was marked as resolved by wlycdgr

This comment has been minimized.

@wlycdgr

wlycdgr Oct 22, 2019
Member

Chuck the trailing comma back in there - we put them there so that property additions show up neatly as one-line changes)

});
/**
* Bind Panel view component action creators using Redux's bindActionCreators
@@ -87,11 +87,18 @@
font-family: 'Roboto Condensed';
letter-spacing: .5px;
color: #FFFFFF;
line-height: 36px;
}
.InsightsModal__link {
font-family: 'Roboto';
font-size: 15px;
color: #4a4a4a;
&:hover {
cursor: pointer;
color: $ghosty-blue;
text-decoration: underline;
text-decoration-color: $link-blue;
}

}
.InsightsModal__otherOptionsContainer {
@@ -115,6 +115,7 @@ class ConfData {
_initProperty('hide_alert_trusted', false);
_initProperty('ignore_first_party', true);
_initProperty('import_callout_dismissed', true);
_initProperty('insights_promo_modal_last_seen', 0);
_initProperty('install_random_number', 0);
_initProperty('install_date', 0);
_initProperty('is_expanded', false);
@@ -16,6 +16,8 @@ import conf from './Conf';
import { log, prefsSet, prefsGet } from '../utils/common';
import { getActiveTab, processUrlQuery } from '../utils/utils';
import rewards from './Rewards';
import { sendMessage } from '../../app/panel/utils/msg';
// import getUserSubscriptionData from './Account';

// CONSTANTS
const FREQUENCIES = { // in milliseconds
@@ -209,6 +211,7 @@ class Metrics {
this._recordActive();
break;
case 'engaged':
this._recordEngagedWithRepeats();
This conversation was marked as resolved by wlycdgr

This comment has been minimized.

@wlycdgr

wlycdgr Oct 22, 2019
Member

With the refactor of the way repeats are tracked, I think you can consolidate these functions to avoid the calculashun duplicashun

this._recordEngaged();
break;

@@ -748,19 +751,68 @@ class Metrics {
*/
_recordEngaged() {
const engaged_daily_velocity = conf.metrics.engaged_daily_velocity || [];
const today = Math.floor(Number(new Date().getTime()) / 86400000);
const today = Math.floor(Number(new Date().getTime()) / 86400000); // Today's time
engaged_daily_velocity.sort();
if (!engaged_daily_velocity.includes(today)) {
engaged_daily_velocity.push(today);
if (engaged_daily_velocity.length > 7) {
engaged_daily_velocity.shift();
}
}
conf.metrics.engaged_daily_velocity = engaged_daily_velocity;

conf.metrics.engaged_daily_velocity = engaged_daily_velocity;
this._sendReq('engaged', ['daily', 'weekly', 'monthly']);
}

/**
* Record Engaged event multiple times in a day
* TODO: Save engaged_daily_velocity_with_repeats to chrome extension storage.
* Current Result: engaged_daily_velocity_with_repeats is saved inside the chrome extension storage, but always is an array with 1 element (today).
* This suggests that conf.metrics.engaged_daily_velocity_with_repeats is an empty array in the beginning, but console.logs are showing correct logic.
* What I have tried: JSON.stringifying the object, using ES6 spread instead of the push since setting an array directly seems to work, checking to see if conf.metrics.engaged_daily_velocity_with_repeats is undefined
* @private
*/
_recordEngagedWithRepeats() {
const engaged_daily_velocity_with_repeats = conf.metrics.engaged_daily_velocity_with_repeats || [];
console.log('Accessing engaged_daily_velocity_with_repeats: ', engaged_daily_velocity_with_repeats);
const today = Math.floor(Number(new Date().getTime()) / 86400000); // Today's time
engaged_daily_velocity_with_repeats.push(today);
conf.metrics.engaged_daily_velocity_with_repeats = engaged_daily_velocity_with_repeats;
console.log('Accessing engaged_daily_velocity_with_repeats after pushing today: ', engaged_daily_velocity_with_repeats);
if (this._hasEngagedFrequently()) {
sendMessage('hasEngagedFrequently', '', 'metrics');
}
}

/**
* Toggle the insights promotion if a user has opened the panel 3 times per day for at least 3 days in the past 7 days
* @private
*/
_hasEngagedFrequently = () => {
const today = new Date().getTime();
const THIRTY_DAYS = 1000 * 60 * 60 * 24 * 30;
const insights_promo_modal_last_seen = Number(conf.insights_promo_modal_last_seen) || null; // TODO: Add logic for plus_promotion_last_seen
const hasSeenPromotionInPastMonth = today - insights_promo_modal_last_seen <= THIRTY_DAYS;
if (!hasSeenPromotionInPastMonth) {
const { engaged_daily_velocity_with_repeats } = conf.metrics;
const pastSevenDays = Array.from(new Set(engaged_daily_velocity_with_repeats));
let timesPerWeek = 0;

for (let i = 0; i < pastSevenDays.length; i++) {
const engagementsEachDay = engaged_daily_velocity_with_repeats.filter(day => day === pastSevenDays[i]).length;
if (engagementsEachDay >= 3) {
timesPerWeek++;
}
}

if (timesPerWeek >= 3) {
conf.insights_promo_modal_last_seen = today;
return true;
}
}
return false;
}

/**
* Repeat sending active request every month
* if computer is continuously on.
ProTip! Use n and p to navigate between commits in a pull request.