From 6adc532e8aab4cab65634f6dc22d59e3951ce62d Mon Sep 17 00:00:00 2001 From: Vinoth kumar Date: Mon, 5 Aug 2024 22:54:40 +0100 Subject: [PATCH] Adding custom events for analytics --- src/actions/app.js | 4 +++- src/components/validate/validate-rules.js | 2 ++ src/containers/app/app-container.js | 2 ++ src/containers/home/home-container.js | 13 +++++++------ src/containers/ruleset/ruleset-container.js | 2 ++ src/data-objects/footer-links.json | 2 +- src/utils/gevents.js | 8 ++++++++ 7 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 src/utils/gevents.js diff --git a/src/actions/app.js b/src/actions/app.js index 324d71d..bac1943 100644 --- a/src/actions/app.js +++ b/src/actions/app.js @@ -1,4 +1,5 @@ import { UPDATE_NAV_STATE, LOG_IN } from './action-types'; +import { sendGevents } from '../utils/gevents'; export function updateState(flag) { @@ -8,7 +9,8 @@ export function updateState(flag) { }); } -export function login() { +export function login(action) { + sendGevents({ narrative: action, name: 'Login'}); return ({ type: LOG_IN, }); diff --git a/src/components/validate/validate-rules.js b/src/components/validate/validate-rules.js index 86f8a9f..8c79c9e 100644 --- a/src/components/validate/validate-rules.js +++ b/src/components/validate/validate-rules.js @@ -10,6 +10,7 @@ import * as Message from '../../constants/messages'; import { validateRuleset } from '../../validations/rule-validation'; import Loader from '../loader/loader'; import { ViewOutcomes } from '../attributes/view-attributes'; +import { sendGevents } from '../../utils/gevents'; class ValidateRules extends Component { @@ -65,6 +66,7 @@ class ValidateRules extends Component { }).catch((e) => { this.setState({loading: false, error: true, errorMessage: e.error, result: true, }); }); + sendGevents({ narrative: 'validate rules', name: 'Validate' }); } attributeItems = () => { diff --git a/src/containers/app/app-container.js b/src/containers/app/app-container.js index eea1130..84ef70a 100644 --- a/src/containers/app/app-container.js +++ b/src/containers/app/app-container.js @@ -8,6 +8,7 @@ import { updateRulesetIndex } from '../../actions/ruleset'; import { updateState } from '../../actions/app'; import { createHashHistory } from 'history'; import ApperanceContext from '../../context/apperance-context'; +import { sendGevents } from '../../utils/gevents'; class ApplicationContainer extends Component { @@ -21,6 +22,7 @@ class ApplicationContainer extends Component { const theme = { ...this.state.theme, background: value }; document.body.className = value; this.setState({ theme }); + sendGevents({ narrative: 'value', name: 'Theme' }); } this.state = {theme: { background: 'light', toggleBackground: this.toggleBackground }}; } diff --git a/src/containers/home/home-container.js b/src/containers/home/home-container.js index d7d12c9..7dbffb4 100644 --- a/src/containers/home/home-container.js +++ b/src/containers/home/home-container.js @@ -13,6 +13,7 @@ import Notification from '../../components/notification/notification'; import { RULE_AVAILABLE_UPLOAD, RULE_UPLOAD_ERROR } from '../../constants/messages'; import ApperanceContext from '../../context/apperance-context'; import { faCloudArrowUp } from '@fortawesome/free-solid-svg-icons' +import { sendGevents } from '../../utils/gevents'; function readFile(file, cb) { @@ -120,14 +121,14 @@ class HomeContainer extends Component { handleUpload() { if(this.state.ruleset.length > 0) { this.props.uploadRuleset(this.state.ruleset); - this.navigate('./ruleset'); + this.navigate('./ruleset', 'upload'); } } - navigate(location) { + navigate(location, action) { const history = createHashHistory(); - this.props.login(); - history.push(location); + this.props.login(action); + history.push(location); } render() { @@ -147,7 +148,7 @@ class HomeContainer extends Component {
@@ -183,7 +184,7 @@ const mapStateToProps = (state) => ({ const mapDispatchToProps = (dispatch) => ({ - login: () => dispatch(login()), + login: (action) => dispatch(login(action)), uploadRuleset: (ruleset) => dispatch(uploadRuleset(ruleset)), }); diff --git a/src/containers/ruleset/ruleset-container.js b/src/containers/ruleset/ruleset-container.js index 1f4cdb6..a2dc78b 100644 --- a/src/containers/ruleset/ruleset-container.js +++ b/src/containers/ruleset/ruleset-container.js @@ -15,6 +15,7 @@ import * as Message from '../../constants/messages'; import { groupBy } from 'lodash/collection'; import RuleErrorBoundary from '../../components/error/ruleset-error'; import SweetAlert from 'react-bootstrap-sweetalert'; +import { sendGevents } from '../../utils/gevents'; const tabs = [{name: 'Facts'}, {name: 'Decisions'}, {name: 'Validate'}, {name: 'Generate'}]; class RulesetContainer extends Component { @@ -40,6 +41,7 @@ class RulesetContainer extends Component { link.href = url; link.click(); this.setState({ generateFlag: true }); + sendGevents({ narrative: 'generate', name: 'Ruleset' }); } cancelAlert() { diff --git a/src/data-objects/footer-links.json b/src/data-objects/footer-links.json index 4e8a196..8f7c204 100644 --- a/src/data-objects/footer-links.json +++ b/src/data-objects/footer-links.json @@ -1,7 +1,7 @@ [ { - "label": "v1.0.0" + "label": "v1.2.0" }, { "label": "Report issue", diff --git a/src/utils/gevents.js b/src/utils/gevents.js new file mode 100644 index 0000000..972f86b --- /dev/null +++ b/src/utils/gevents.js @@ -0,0 +1,8 @@ + + +export const sendGevents = (event) => { + gtag('event', event.name, { + action: event.narrative, + pageName: event.pageName || event.name, + }); +}; \ No newline at end of file