Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cboard-org/cboard
Browse files Browse the repository at this point in the history
  • Loading branch information
RodriSanchez1 committed Dec 18, 2023
2 parents 595861d + 03eb5c0 commit c1f172a
Show file tree
Hide file tree
Showing 9 changed files with 552 additions and 45 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"private": false,
"license": "GPL-3.0-only",
"dependencies": {
"@analytics-debugger/ga4mp": "git+https://github.com/RodriSanchez1/ga4mp.git#fix/fullVersionList",
"@cospired/i18n-iso-languages": "^2.2.0",
"@crowdin/crowdin-api-client": "^1.26.0",
"@ctrl/react-adsense": "^1.7.0",
Expand Down Expand Up @@ -91,10 +92,11 @@
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"babel-plugin-transform-import-meta": "^2.2.1",
"@craco/craco": "^7.1.0",
"@types/mime-types": "^2.1.1",
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.0",
"babel-jest": "^29.7.0",
"babel-plugin-transform-import-meta": "^2.2.1",
"decompress-zip": "^0.3.1",
"enzyme": "^3.11.0",
"enzyme-to-json": "3.3.5",
Expand Down Expand Up @@ -125,7 +127,7 @@
},
"jest": {
"transformIgnorePatterns": [
"node_modules/(?!idb|microsoft-cognitiveservices-speech-sdk)"
"node_modules/(?!idb|microsoft-cognitiveservices-speech-sdk|@analytics-debugger/ga4mp)"
],
"moduleNameMapper": {
"\\.(css|less)$": "<rootDir>/src/__mocks__/styleMock.js"
Expand Down
13 changes: 9 additions & 4 deletions src/components/Account/Login/Login.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '../../App/App.actions';
import { getVoiceURI } from '../../../i18n';
import { isCordova, isElectron } from '../../../cordova-util';
import ga4track from '../../../ga4mp';

export function loginSuccess(payload) {
return dispatch => {
Expand All @@ -22,9 +23,11 @@ export function loginSuccess(payload) {
payload
});
if (payload.isFirstLogin) firstLoginActions(dispatch, payload);
if (isCordova() && !isElectron())
if (isCordova())
try {
window.FirebasePlugin.setUserId(payload.id);
isElectron()
? ga4track.setUserId(payload.id)
: window.FirebasePlugin.setUserId(payload.id);
} catch (err) {
console.error(err);
}
Expand All @@ -41,9 +44,11 @@ async function firstLoginActions(dispatch, payload) {
}

export function logout() {
if (isCordova() && !isElectron())
if (isCordova())
try {
window.FirebasePlugin.setUserId(undefined);
isElectron()
? ga4track.setUserId(undefined)
: window.FirebasePlugin.setUserId(undefined);
} catch (err) {
console.error(err);
}
Expand Down
22 changes: 13 additions & 9 deletions src/components/App/App.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
updateConnectivity
} from '../App/App.actions';
import { isCordova, isElectron } from '../../cordova-util';
import ga4track from '../../ga4mp';

export class AppContainer extends Component {
static propTypes = {
/**
Expand Down Expand Up @@ -66,15 +68,17 @@ export class AppContainer extends Component {

const initCVAGa4 = () => {
const { isLogged, userId } = this.props;
if (!isElectron()) {
try {
if (isLogged) {
window.FirebasePlugin.setUserId(userId);
}
window.FirebasePlugin.logEvent('page_view');
} catch (err) {
console.error(err);
}
try {
if (isLogged)
isElectron()
? ga4track.setUserId(userId)
: window.FirebasePlugin.setUserId(userId);

isElectron()
? ga4track.trackEvent('page_view')
: window.FirebasePlugin.logEvent('page_view');
} catch (err) {
console.error(err);
}
};

Expand Down
18 changes: 9 additions & 9 deletions src/components/Board/Board.analytics.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { trackEvent } from '@redux-beacon/google-analytics-gtag';
import { isCordova, cvaTrackEvent } from '../../cordova-util';

import ga4track from '../../ga4mp';
import {
IMPORT_BOARDS,
CREATE_BOARD,
Expand All @@ -27,7 +27,7 @@ const importBoards = trackEvent((action, prevState, nextState) => {
action: 'Import Boards'
};
if (isCordova()) {
cvaTrackEvent(gaEvent.category, gaEvent.action);
cvaTrackEvent(gaEvent.category, gaEvent.action, false, ga4track);
}
return gaEvent;
});
Expand All @@ -46,7 +46,7 @@ const changeBoard = trackEvent((action, prevState, nextState) => {
label: boardName
};
if (isCordova()) {
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label);
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label, ga4track);
}
return gaEvent;
});
Expand All @@ -58,7 +58,7 @@ const createBoard = trackEvent((action, prevState, nextState) => {
label: action.boardName
};
if (isCordova()) {
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label);
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label, ga4track);
}
return gaEvent;
});
Expand All @@ -70,7 +70,7 @@ const createTile = trackEvent((action, prevState, nextState) => {
label: action.tile.label
};
if (isCordova()) {
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label);
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label, ga4track);
}
return gaEvent;
});
Expand All @@ -87,7 +87,7 @@ const deleteTiles = trackEvent((action, prevState, nextState) => {
label: deletedTiles
};
if (isCordova()) {
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label);
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label, ga4track);
}
return gaEvent;
});
Expand All @@ -103,7 +103,7 @@ const editTiles = trackEvent((action, prevState, nextState) => {
label: editedTiles
};
if (isCordova()) {
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label);
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label, ga4track);
}
return gaEvent;
});
Expand All @@ -115,7 +115,7 @@ const clickSymbol = trackEvent((action, prevState, nextState) => {
label: action.symbolLabel
};
if (isCordova()) {
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label);
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label, ga4track);
}
return gaEvent;
});
Expand All @@ -127,7 +127,7 @@ const clickOutput = trackEvent((action, prevState, nextState) => {
label: action.outputPhrase
};
if (isCordova()) {
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label);
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label, ga4track);
}
return gaEvent;
});
Expand Down
3 changes: 3 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ export const PAYPAL_CLIENT_ID =
// Google related constants
export const GOOGLE_FIREBASE_WEB_CLIENT_ID =
process.env.REACT_APP_GOOGLE_FIREBASE_WEB_CLIENT_ID || '';

// Google Analytics related constants
export const GA4_MEASUREMENT_ID = 'G-60S79265FY';
10 changes: 7 additions & 3 deletions src/cordova-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const configFacebookPlugin = () => {
);
};

export const cvaTrackEvent = (category, action, label) => {
export const cvaTrackEvent = (category, action, label, ga4mp) => {
try {
const convertEventToNewNomenclature = name => {
const inLowerCase = name.toLowerCase();
Expand All @@ -154,9 +154,13 @@ export const cvaTrackEvent = (category, action, label) => {
: {
event_category: category
};
if (!isElectron()) window.FirebasePlugin.logEvent(event_name, eventOptions);

if (isAndroid() || isIOS())
window.FirebasePlugin.logEvent(event_name, eventOptions);

if (isElectron()) ga4mp.trackEvent(event_name, eventOptions);
} catch (err) {
console.log(err.message);
console.error(err.message);
}
};

Expand Down
11 changes: 11 additions & 0 deletions src/ga4mp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ga4mp from '@analytics-debugger/ga4mp';
import { GA4_MEASUREMENT_ID } from './constants';

const ga4track = ga4mp([GA4_MEASUREMENT_ID], {
non_personalized_ads: true,
debug: false,
user_agent:
'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
});

export default ga4track;
9 changes: 5 additions & 4 deletions src/providers/SpeechProvider/SpeechProvider.analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
EMPTY_VOICES
} from './SpeechProvider.constants';
import { isCordova, cvaTrackEvent } from '../../cordova-util';
import ga4track from '../../ga4mp';

const changeVoice = trackEvent((action, prevState, nextState) => {
const gaEvent = {
Expand All @@ -16,7 +17,7 @@ const changeVoice = trackEvent((action, prevState, nextState) => {
label: action ? action.voiceURI : EMPTY_VOICES
};
if (isCordova()) {
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label);
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label, ga4track);
}
return gaEvent;
});
Expand All @@ -28,7 +29,7 @@ const changePitch = trackEvent((action, prevState, nextState) => {
label: action.pitch
};
if (isCordova()) {
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label);
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label, ga4track);
}
return gaEvent;
});
Expand All @@ -40,7 +41,7 @@ const changeRate = trackEvent((action, prevState, nextState) => {
label: action.rate
};
if (isCordova()) {
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label);
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label, ga4track);
}
return gaEvent;
});
Expand All @@ -52,7 +53,7 @@ const startSpeech = trackEvent((action, prevState, nextState) => {
label: action.text
};
if (isCordova()) {
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label);
cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label, ga4track);
}
return gaEvent;
});
Expand Down
Loading

0 comments on commit c1f172a

Please sign in to comment.