Skip to content

Commit c662104

Browse files
committed
feat: implement show by chance and random delay
1 parent f1aea43 commit c662104

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

config.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ relativeURLs = false
112112
apiUrl = "https://cmu-delphi.github.io/delphi-epidata"
113113
twitter = "CmuDelphi"
114114
feedbackForm = "https://docs.google.com/forms/d/e/1FAIpQLSffGhrCsZmDSF4Lbeg9lB-Gp_Uf7z7D9ust-vXk1F5V1SElig/viewform?usp=pp_url&entry.1245962748="
115-
feedbackRequest = "We'd love to hear from you"
116-
feedbackDelay = 30 # wait for initial 30sec to show the notification
115+
feedbackLikelihoodMobile = 0.2
116+
feedbackLikelihoodDesktop = 1
117+
feedbackDelayMin = 10 # in sec
118+
feedbackDelayMax = 100 # in sec
117119
feedbackDuration = 60 # show it for 60sec

themes/delphi/assets/js/feedback-button.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,18 @@ import UIkit from "uikit/dist/js/uikit.js";
4646
const container = document.querySelector(".feedback-popup-container");
4747

4848
if (container && !wasRecentlySubmitted()) {
49-
const delay = Number.parseInt(container.dataset.delay, 10) * 1000;
49+
const delayMin = Number.parseInt(container.dataset.delayMin, 10) * 1000;
50+
const delayMax = Number.parseInt(container.dataset.delayMax, 10) * 1000;
51+
const delay = delayMin + Math.random() * (delayMax - delayMin);
52+
53+
const feedbackLikelihoodDesktop = Number.parseFloat(container.dataset.likeDesktop);
54+
const feedbackLikelihoodMobile = Number.parseFloat(container.dataset.likeMobile);
55+
const isMobile = window.matchMedia("only screen and (max-width: 700px)").matches;
56+
57+
const showByChance =
58+
(isMobile && Math.random() <= feedbackLikelihoodMobile) ||
59+
(!isMobile && Math.random() <= feedbackLikelihoodDesktop);
60+
5061
const duration = Number.parseInt(container.dataset.duration, 10) * 1000;
5162
const formLink = container.dataset.href;
5263

@@ -70,6 +81,8 @@ import UIkit from "uikit/dist/js/uikit.js";
7081
});
7182
};
7283
// initial delay
73-
setTimeout(showFeedbackNotification, delay);
84+
if (showByChance) {
85+
setTimeout(showFeedbackNotification, delay);
86+
}
7487
}
7588
})();

themes/delphi/layouts/partials/footer.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ <h5 class="uk-text-bold">Contact</h5>
5555
class="feedback-popup-container"
5656
style="display: none"
5757
data-href="{{ .Site.Params.feedbackForm }}"
58-
data-delay="{{ .Site.Params.feedbackDelay }}"
58+
data-like-mobile="{{ .Site.Params.feedbackLikelihoodMobile }}"
59+
data-like-desktop="{{ .Site.Params.feedbackLikelihoodDesktop }}"
60+
data-delay-min="{{ .Site.Params.feedbackDelayMin }}"
61+
data-delay-max="{{ .Site.Params.feedbackDelayMax }}"
5962
data-duration="{{ .Site.Params.feedbackDuration }}"
6063
>
6164
{{ partial "font-awesome.html" "solid/question-circle" }}

0 commit comments

Comments
 (0)