From a2ba1951e155914a9b80ec2b4f727c9ea7424448 Mon Sep 17 00:00:00 2001 From: PoojaB26 Date: Tue, 30 Jul 2024 19:27:09 +0530 Subject: [PATCH] Add feedback widget with gtag event --- package-lock.json | 15 ++++++++++++- package.json | 3 ++- src/components/Feedback/index.js | 37 ++++++++++++++++++++++++++++++++ yarn.lock | 9 ++++++-- 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 src/components/Feedback/index.js diff --git a/package-lock.json b/package-lock.json index 168462f6..584bd733 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,8 @@ "clsx": "^2.0.0", "prism-react-renderer": "^2.3.0", "react": "^18.0.0", - "react-dom": "^18.0.0" + "react-dom": "^18.0.0", + "react-simple-star-rating": "^5.1.7" }, "devDependencies": { "@docusaurus/module-type-aliases": "3.1.1", @@ -12330,6 +12331,18 @@ "react": ">=15" } }, + "node_modules/react-simple-star-rating": { + "version": "5.1.7", + "resolved": "https://registry.npmjs.org/react-simple-star-rating/-/react-simple-star-rating-5.1.7.tgz", + "integrity": "sha512-NTFkW8W3uwvI82Fv7JW5i7gmDjEZKxJmj+Z9vn+BjYIXT6ILdnU9qnSUP2cWrWN/WAUlue81f9SgM4CQcenltQ==", + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "react": ">=18.0.0", + "react-dom": ">=18.0.0" + } + }, "node_modules/readable-stream": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", diff --git a/package.json b/package.json index 477ad0fe..77798dd9 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "clsx": "^2.0.0", "prism-react-renderer": "^2.3.0", "react": "^18.0.0", - "react-dom": "^18.0.0" + "react-dom": "^18.0.0", + "react-simple-star-rating": "^5.1.7" }, "devDependencies": { "@docusaurus/module-type-aliases": "3.1.1", diff --git a/src/components/Feedback/index.js b/src/components/Feedback/index.js new file mode 100644 index 00000000..ff4f5e39 --- /dev/null +++ b/src/components/Feedback/index.js @@ -0,0 +1,37 @@ +import React, { useState, useEffect } from 'react'; +import { Rating } from 'react-simple-star-rating'; + +const Feedback = () => { + const [rating, setRating] = useState(0); + + const handleRating = (rate) => { + setRating(rate); + console.log(window.location.pathname.toString()) + + if (window.gtag) { + window.gtag('event', 'rating', { + event_category: 'Feedback', + event_label: window.location.pathname, + value: rate, + }); + } + }; + + return ( +
+ + {/*
*/} + {/* Your Rating: {rating / 20} stars*/} + {/*
*/} +
+ ); +}; + +export default Feedback; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 26527702..f03da678 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6956,7 +6956,7 @@ react-dev-utils@^12.0.1: strip-ansi "^6.0.1" text-table "^0.2.0" -react-dom@*, "react-dom@^16.6.0 || ^17.0.0 || ^18.0.0", react-dom@^18.0.0, "react-dom@>= 16.8.0 < 19.0.0": +react-dom@*, "react-dom@^16.6.0 || ^17.0.0 || ^18.0.0", react-dom@^18.0.0, "react-dom@>= 16.8.0 < 19.0.0", react-dom@>=18.0.0: version "18.3.1" resolved "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz" integrity sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw== @@ -7052,7 +7052,12 @@ react-router@^5.3.4, react-router@>=5, react-router@5.3.4: tiny-invariant "^1.0.2" tiny-warning "^1.0.0" -react@*, "react@^16.13.1 || ^17.0.0 || ^18.0.0", "react@^16.6.0 || ^17.0.0 || ^18.0.0", react@^18.0.0, react@^18.3.1, "react@>= 16.8.0 < 19.0.0", react@>=15, react@>=16, react@>=16.0.0: +react-simple-star-rating@^5.1.7: + version "5.1.7" + resolved "https://registry.npmjs.org/react-simple-star-rating/-/react-simple-star-rating-5.1.7.tgz" + integrity sha512-NTFkW8W3uwvI82Fv7JW5i7gmDjEZKxJmj+Z9vn+BjYIXT6ILdnU9qnSUP2cWrWN/WAUlue81f9SgM4CQcenltQ== + +react@*, "react@^16.13.1 || ^17.0.0 || ^18.0.0", "react@^16.6.0 || ^17.0.0 || ^18.0.0", react@^18.0.0, react@^18.3.1, "react@>= 16.8.0 < 19.0.0", react@>=15, react@>=16, react@>=16.0.0, react@>=18.0.0: version "18.3.1" resolved "https://registry.npmjs.org/react/-/react-18.3.1.tgz" integrity sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==