PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.1.13
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.1.13
11.3.75 11.3.73 11.3.71 11.3.70 11.3.69 11.3.64 11.3.65 11.3.62 11.3.61 11.3.56 11.3.58 11.0.31 11.0.52 11.0.54 11.0.56 11.0.58 11.0.7 11.1.10 11.1.11 11.1.13 11.1.14 11.1.15 11.1.2 11.1.20 11.1.21 All 73 releases
leadin / scripts / entries / reviewBanner.ts

reviewBanner.ts in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.1.13, at scripts/entries/reviewBanner.ts

65 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import $ from 'jquery';
2 import {
3 getOrCreateBackgroundApp,
4 initBackgroundApp,
5 } from '../utils/backgroundAppUtils';
6 import { domElements } from '../constants/selectors';
7 import { refreshToken, activationTime } from '../constants/leadinConfig';
8 import { ProxyMessages } from '../iframe/integratedMessages';
9
10 const REVIEW_BANNER_INTRO_PERIOD_DAYS = 15;
11
12 const userIsAfterIntroductoryPeriod = () => {
13 const activationDate = new Date(+activationTime * 1000);
14 const currentDate = new Date();
15 const timeElapsed = new Date(
16 currentDate.getTime() - activationDate.getTime()
17 );
18
19 return timeElapsed.getUTCDate() - 1 >= REVIEW_BANNER_INTRO_PERIOD_DAYS;
20 };
21
22 /**
23 * Adds some methods to window when review banner is
24 * displayed to monitor events
25 */
26 export function initMonitorReviewBanner() {
27 if (refreshToken) {
28 const embedder = getOrCreateBackgroundApp(refreshToken);
29 const container = $(domElements.reviewBannerContainer);
30 if (container && userIsAfterIntroductoryPeriod()) {
31 $(domElements.reviewBannerLeaveReviewLink)
32 .off('click')
33 .on('click', () => {
34 embedder.postMessage({
35 key: ProxyMessages.TrackReviewBannerInteraction,
36 });
37 });
38
39 $(domElements.reviewBannerDismissButton)
40 .off('click')
41 .on('click', () => {
42 embedder.postMessage({
43 key: ProxyMessages.TrackReviewBannerDismissed,
44 });
45 });
46
47 embedder
48 .postAsyncMessage({
49 key: ProxyMessages.FetchContactsCreateSinceActivation,
50 payload: +activationTime * 1000,
51 })
52 .then(({ total }: any) => {
53 if (total >= 5) {
54 container.removeClass('leadin-review-banner--hide');
55 embedder.postMessage({
56 key: ProxyMessages.TrackReviewBannerRender,
57 });
58 }
59 });
60 }
61 }
62 }
63
64 initBackgroundApp(initMonitorReviewBanner);
65