Skip to content

Commit

Permalink
Adding custom events for analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
vinzdeveloper committed Aug 5, 2024
1 parent dcc588e commit 6adc532
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/actions/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { UPDATE_NAV_STATE, LOG_IN } from './action-types';
import { sendGevents } from '../utils/gevents';


export function updateState(flag) {
Expand All @@ -8,7 +9,8 @@ export function updateState(flag) {
});
}

export function login() {
export function login(action) {
sendGevents({ narrative: action, name: 'Login'});
return ({
type: LOG_IN,
});
Expand Down
2 changes: 2 additions & 0 deletions src/components/validate/validate-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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 = () => {
Expand Down
2 changes: 2 additions & 0 deletions src/containers/app/app-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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 }};
}
Expand Down
13 changes: 7 additions & 6 deletions src/containers/home/home-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand All @@ -147,7 +148,7 @@ class HomeContainer extends Component {
</div>
<div className="btn-group">
<Button label={"Upload"} onConfirm={this.handleUpload} classname="primary-btn" type="button" />
{!this.props.loggedIn && <Button label={"Create"} onConfirm={() => this.navigate('./create-ruleset')} classname="primary-btn" type="button" disabled={this.state.files.length > 0} />}
{!this.props.loggedIn && <Button label={"Create"} onConfirm={() => this.navigate('./create-ruleset', 'create')} classname="primary-btn" type="button" disabled={this.state.files.length > 0} />}
</div>
</TitlePanel>
</div>
Expand Down Expand Up @@ -183,7 +184,7 @@ const mapStateToProps = (state) => ({

const mapDispatchToProps = (dispatch) => ({

login: () => dispatch(login()),
login: (action) => dispatch(login(action)),
uploadRuleset: (ruleset) => dispatch(uploadRuleset(ruleset)),

});
Expand Down
2 changes: 2 additions & 0 deletions src/containers/ruleset/ruleset-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -40,6 +41,7 @@ class RulesetContainer extends Component {
link.href = url;
link.click();
this.setState({ generateFlag: true });
sendGevents({ narrative: 'generate', name: 'Ruleset' });
}

cancelAlert() {
Expand Down
2 changes: 1 addition & 1 deletion src/data-objects/footer-links.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[

{
"label": "v1.0.0"
"label": "v1.2.0"
},
{
"label": "Report issue",
Expand Down
8 changes: 8 additions & 0 deletions src/utils/gevents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


export const sendGevents = (event) => {
gtag('event', event.name, {
action: event.narrative,
pageName: event.pageName || event.name,
});
};

0 comments on commit 6adc532

Please sign in to comment.