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

feat(dsfr): ajout d'un detecteur d'adblock pour éviter qu'un usager partage un message dans le vide #6226

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { PIWIK_URL } from "../../../config";

export const detectAdBlockCall = async (): Promise<boolean> => {
return fetch(PIWIK_URL, {
method: "HEAD",
mode: "no-cors",
cache: "no-store",
})
.then(({ redirected }) => {
return redirected;
})
.catch(() => {
return true;
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { fr } from "@codegouvfr/react-dsfr";

export const FeedbackAdblock = () => {
return (
<>
<h2 className={fr.cx("fr-h5")}>
Nous n&apos;avons pas pu envoyer votre réponse
</h2>
<p>
Pour soumettre votre avis, merci de désactiver temporairement votre
bloqueur de publicité et recharger la page.
</p>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { FeedbackDefault } from "./FeedbackDefault";
import { FeedbackContent, FeedbackDataSent } from "./FeedbackContent";
import { FeedbackAnswered } from "./FeedbackAnswered";
import { useFeedbackEvents } from "./tracking";
import { FeedbackAdblock } from "./FeedbackAdblock";
import { detectAdBlockCall } from "./AdBlockDetector";

export const Feedback = () => {
const [viewFeedback, setViewFeedback] = useState<
"yes" | "no" | "default" | "answered"
"yes" | "no" | "default" | "answered" | "adBlockDetected"
>("default");
const {
emitNegativeFeedback,
Expand All @@ -18,13 +20,15 @@ export const Feedback = () => {
emitFeedbackSuggestion,
} = useFeedbackEvents();

const onClickNo = () => {
setViewFeedback("no");
const onClickNo = async () => {
const detectAddBlock = await detectAdBlockCall();
setViewFeedback(detectAddBlock ? "adBlockDetected" : "no");
emitNegativeFeedback();
};

const onClickYes = () => {
setViewFeedback("yes");
const onClickYes = async () => {
const detectAddBlock = await detectAdBlockCall();
setViewFeedback(detectAddBlock ? "adBlockDetected" : "yes");
emitPositiveFeedback();
};

Expand All @@ -48,6 +52,7 @@ export const Feedback = () => {
<FeedbackContent onSubmit={onSubmit} type="positive" />
)}
{viewFeedback === "answered" && <FeedbackAnswered />}
{viewFeedback === "adBlockDetected" && <FeedbackAdblock />}
</div>
);
};
Loading