Skip to content

Commit

Permalink
Send download and copy events to Google Analytics
Browse files Browse the repository at this point in the history
Also cleans up the message about RoboShield in the generated robots.txt
text.
  • Loading branch information
kilemensi committed Aug 16, 2024
1 parent aec1306 commit 4322f51
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
20 changes: 11 additions & 9 deletions apps/roboshield/src/components/Finish/Finish.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Box, Snackbar } from "@mui/material";
import { sendGAEvent } from "@next/third-parties/google";
import { useEffect, useState } from "react";

import Code from "../Code";
import Code from "@/roboshield/components/Code";
import StepperNav from "@/roboshield/components/StepperNav";

import SkipToLastStep from "@/roboshield/components/SkipToLastStep";
import StepHint from "@/roboshield/components/StepHint";
import { useGlobalState } from "@/roboshield/context/GlobalContext";
import { generateRobots } from "@/roboshield/lib/robots";
import { StepComponent } from "@/roboshield/types/stepComponent";
import { downloadFile } from "@/roboshield/utils/file";
import SkipToLastStep from "@/roboshield/components/SkipToLastStep";
import StepHint from "@/roboshield/components/StepHint";

interface Props extends StepComponent {
handleReset: () => void;
Expand Down Expand Up @@ -37,27 +38,28 @@ export default function Finish({
});
}

const getCopyMetadata = () => {
const date = new Date().toISOString();
const url = window.location.href;
return `${code}\n\n\n# Generated on: ${date}\n# URL: ${url}\n\n`;
const reportShieldEvent = (event: string) => {
const value = new Date().toISOString();
sendGAEvent("event", event, { value: "xyz" });
};

const handleDownload = async () => {
reportShieldEvent("download");
const filename = "robots.txt";
if (!saved) {
await saveData();
setSaved(true);
}
await downloadFile(filename, getCopyMetadata());
await downloadFile(filename, code);
};

const handleCopy = async () => {
reportShieldEvent("copy");
if (!saved) {
await saveData();
setSaved(true);
}
navigator.clipboard.writeText(getCopyMetadata());
navigator.clipboard.writeText(code);
setShowSnackbar(true);
};

Expand Down
2 changes: 1 addition & 1 deletion apps/roboshield/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const platforms: Platform[] = [

export const configureCrawlDelay = (delay: number) => {
const comment =
"#Crawl-delay Specifies the minimum interval (in seconds)\n#for a robot to wait after loading one page, before starting to load another.\n";
"# Crawl-delay Specifies the minimum interval (in seconds)\n#for a robot to wait after loading one page, before starting to load another.\n";
return `${comment}Crawl-delay: ${delay}\n\n`;
};

Expand Down
6 changes: 3 additions & 3 deletions apps/roboshield/src/lib/robots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const mergeAndSortBots = (existingBots: Robot[], newBots: Robot[]) => {
};

export async function generateRobots(state: GlobalState) {
let robots = ``;
let robots = `
`;

if (state.crawlDelay && state.crawlDelay > 0) {
robots += configureCrawlDelay(state.crawlDelay);
Expand Down Expand Up @@ -73,8 +74,7 @@ export async function generateRobots(state: GlobalState) {
robots += configureSitemaps(validSitemaps);
}
}

return robots;
return `${robots}\n# Generatedy by RoboShield (https://roboshield.trustlab.africa)\n`;
}

export const validateRobots = (robots: string) => {
Expand Down

0 comments on commit 4322f51

Please sign in to comment.