From a60f04477bbdcf1d0e6d5a8b6b1c478f836cd21c Mon Sep 17 00:00:00 2001 From: martin bedouret Date: Mon, 25 Nov 2019 09:29:40 -0300 Subject: [PATCH 1/6] Fix google analytics --- src/analytics.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/analytics.js b/src/analytics.js index 510a4ac50..965704c34 100644 --- a/src/analytics.js +++ b/src/analytics.js @@ -3,7 +3,7 @@ import GoogleAnalyticsGtag from '@redux-beacon/google-analytics-gtag'; import offlineWeb from '@redux-beacon/offline-web'; // import logger from '@redux-beacon/logger'; -import { isCordova } from './cordova-util'; +import { isCordova, onCordovaReady } from './cordova-util'; import boardEventsMap from './components/Board/Board.analytics'; import speechEventsMap from './providers/SpeechProvider/SpeechProvider.analytics'; @@ -23,7 +23,7 @@ const gaMiddleware = createMiddleware(eventsMap, ga, { }); if (isCordova()) { - window.ga.startTrackerWithId('UA-152065055-1', 20); + onCordovaReady(window.ga.startTrackerWithId('UA-152065055-1', 20)); } export default gaMiddleware; From 7fe13dcf583a593e3f1aa30988b48a5be4e6803b Mon Sep 17 00:00:00 2001 From: martin bedouret Date: Mon, 25 Nov 2019 10:29:23 -0300 Subject: [PATCH 2/6] wip --- src/analytics.js | 6 +++++- src/components/Board/Board.analytics.js | 16 ++++++++-------- src/cordova-util.js | 8 ++++++++ .../SpeechProvider/SpeechProvider.analytics.js | 10 +++++----- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/analytics.js b/src/analytics.js index 965704c34..c960365c7 100644 --- a/src/analytics.js +++ b/src/analytics.js @@ -23,7 +23,11 @@ const gaMiddleware = createMiddleware(eventsMap, ga, { }); if (isCordova()) { - onCordovaReady(window.ga.startTrackerWithId('UA-152065055-1', 20)); + try { + onCordovaReady(window.ga.startTrackerWithId('UA-152065055-1', 20)); + } catch (err) { + console.log(err.message); + } } export default gaMiddleware; diff --git a/src/components/Board/Board.analytics.js b/src/components/Board/Board.analytics.js index 115ec5206..60a2fd283 100644 --- a/src/components/Board/Board.analytics.js +++ b/src/components/Board/Board.analytics.js @@ -1,5 +1,5 @@ import { trackEvent } from '@redux-beacon/google-analytics-gtag'; -import { isCordova } from '../../cordova-util'; +import { isCordova, cvaTrackEvent } from '../../cordova-util'; import { IMPORT_BOARDS, @@ -26,7 +26,7 @@ const importBoards = trackEvent((action, prevState, nextState) => { action: 'Import Boards' }; if (isCordova()) { - window.ga.trackEvent(gaEvent.category, gaEvent.action); + cvaTrackEvent(gaEvent.category, gaEvent.action); } return gaEvent; }); @@ -42,7 +42,7 @@ const changeBoard = trackEvent((action, prevState, nextState) => { label: boardName }; if (isCordova()) { - window.ga.trackEvent(gaEvent.category, gaEvent.action, gaEvent.label); + cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label); } return gaEvent; }); @@ -54,7 +54,7 @@ const createBoard = trackEvent((action, prevState, nextState) => { label: action.boardName }; if (isCordova()) { - window.ga.trackEvent(gaEvent.category, gaEvent.action, gaEvent.label); + cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label); } return gaEvent; }); @@ -66,7 +66,7 @@ const createTile = trackEvent((action, prevState, nextState) => { label: action.tile.label }; if (isCordova()) { - window.ga.trackEvent(gaEvent.category, gaEvent.action, gaEvent.label); + cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label); } return gaEvent; }); @@ -83,7 +83,7 @@ const deleteTiles = trackEvent((action, prevState, nextState) => { label: deletedTiles }; if (isCordova()) { - window.ga.trackEvent(gaEvent.category, gaEvent.action, gaEvent.label); + cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label); } return gaEvent; }); @@ -99,7 +99,7 @@ const editTiles = trackEvent((action, prevState, nextState) => { label: editedTiles }; if (isCordova()) { - window.ga.trackEvent(gaEvent.category, gaEvent.action, gaEvent.label); + cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label); } return gaEvent; }); @@ -111,7 +111,7 @@ const clickSymbol = trackEvent((action, prevState, nextState) => { label: action.symbolLabel }; if (isCordova()) { - window.ga.trackEvent(gaEvent.category, gaEvent.action, gaEvent.label); + cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label); } return gaEvent; }); diff --git a/src/cordova-util.js b/src/cordova-util.js index 57007e46a..24766f4ab 100644 --- a/src/cordova-util.js +++ b/src/cordova-util.js @@ -3,6 +3,14 @@ export const isCordova = () => !!window.cordova; export const onCordovaReady = onReady => document.addEventListener('deviceready', onReady, false); +export const cvaTrackEvent = (category, action, label) => { + try { + onCordovaReady(window.ga.trackEvent(category, action, label)); + } catch (err) { + console.log(err.message); + } +}; + export const writeCvaFile = async (name, blob) => { if (isCordova()) { return new Promise(function(resolve, reject) { diff --git a/src/providers/SpeechProvider/SpeechProvider.analytics.js b/src/providers/SpeechProvider/SpeechProvider.analytics.js index 1b3c7f16b..fdd01d76a 100644 --- a/src/providers/SpeechProvider/SpeechProvider.analytics.js +++ b/src/providers/SpeechProvider/SpeechProvider.analytics.js @@ -6,7 +6,7 @@ import { CHANGE_RATE, START_SPEECH } from './SpeechProvider.constants'; -import { isCordova } from '../../cordova-util'; +import { isCordova, cvaTrackEvent } from '../../cordova-util'; const changeVoice = trackEvent((action, prevState, nextState) => { const gaEvent = { @@ -15,7 +15,7 @@ const changeVoice = trackEvent((action, prevState, nextState) => { label: action.voiceURI }; if (isCordova()) { - window.ga.trackEvent(gaEvent.category, gaEvent.action, gaEvent.label); + cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label); } return gaEvent; }); @@ -27,7 +27,7 @@ const changePitch = trackEvent((action, prevState, nextState) => { label: action.pitch }; if (isCordova()) { - window.ga.trackEvent(gaEvent.category, gaEvent.action, gaEvent.label); + cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label); } return gaEvent; }); @@ -39,7 +39,7 @@ const changeRate = trackEvent((action, prevState, nextState) => { label: action.rate }; if (isCordova()) { - window.ga.trackEvent(gaEvent.category, gaEvent.action, gaEvent.label); + cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label); } return gaEvent; }); @@ -51,7 +51,7 @@ const startSpeech = trackEvent((action, prevState, nextState) => { label: action.text }; if (isCordova()) { - window.ga.trackEvent(gaEvent.category, gaEvent.action, gaEvent.label); + cvaTrackEvent(gaEvent.category, gaEvent.action, gaEvent.label); } return gaEvent; }); From b314533b40fde004745e41156e15a3e396757174 Mon Sep 17 00:00:00 2001 From: martin bedouret Date: Mon, 25 Nov 2019 11:27:37 -0300 Subject: [PATCH 3/6] wip --- src/cordova-util.js | 1 + src/providers/SpeechProvider/tts.js | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cordova-util.js b/src/cordova-util.js index 24766f4ab..495b72f51 100644 --- a/src/cordova-util.js +++ b/src/cordova-util.js @@ -5,6 +5,7 @@ export const onCordovaReady = onReady => export const cvaTrackEvent = (category, action, label) => { try { + window.ga.startTrackerWithId('UA-152065055-1', 20); onCordovaReady(window.ga.trackEvent(category, action, label)); } catch (err) { console.log(err.message); diff --git a/src/providers/SpeechProvider/tts.js b/src/providers/SpeechProvider/tts.js index 49a62a282..1da570325 100644 --- a/src/providers/SpeechProvider/tts.js +++ b/src/providers/SpeechProvider/tts.js @@ -46,7 +46,10 @@ const tts = { // Get voices depending on platform (browser/cordova) _getPlatformVoices() { - const voices = synth.getVoices(); + let voices = {}; + try { + voices = synth.getVoices(); + } catch (err) {} // On Cordova, voice results are under `._list` return voices._list || voices; }, From fa8588aba549c979ead864aab99438e6d454e1df Mon Sep 17 00:00:00 2001 From: martin bedouret Date: Mon, 25 Nov 2019 13:06:45 -0300 Subject: [PATCH 4/6] wip --- src/cordova-util.js | 17 ++++++++++++----- src/index.js | 5 ++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/cordova-util.js b/src/cordova-util.js index 495b72f51..90a0ae470 100644 --- a/src/cordova-util.js +++ b/src/cordova-util.js @@ -3,13 +3,20 @@ export const isCordova = () => !!window.cordova; export const onCordovaReady = onReady => document.addEventListener('deviceready', onReady, false); +export const initCordovaPlugins = () => { + document.addEventListener('deviceready', onDeviceReady, false); +}; + +function onDeviceReady() { + console.log('now cordova is ready '); +} + export const cvaTrackEvent = (category, action, label) => { try { - window.ga.startTrackerWithId('UA-152065055-1', 20); - onCordovaReady(window.ga.trackEvent(category, action, label)); - } catch (err) { - console.log(err.message); - } + if (window.ga) { + window.ga.trackEvent(category, action, label); + } + } catch (err) {} }; export const writeCvaFile = async (name, blob) => { diff --git a/src/index.js b/src/index.js index 047efd5b5..f282b709f 100644 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,7 @@ import { Provider } from 'react-redux'; import { BrowserRouter, HashRouter, Route } from 'react-router-dom'; import { PersistGate } from 'redux-persist/es/integration/react'; import App from './components/App'; -import { isCordova, onCordovaReady } from './cordova-util'; +import { isCordova, onCordovaReady, initCordovaPlugins } from './cordova-util'; import './index.css'; import './polyfills'; import LanguageProvider from './providers/LanguageProvider'; @@ -38,3 +38,6 @@ const renderApp = () => { }; isCordova() ? onCordovaReady(renderApp) : renderApp(); +if (isCordova()) { + initCordovaPlugins(); +} From 2ff0a701e62aa7def3179cc4678b23b4c26bcc7d Mon Sep 17 00:00:00 2001 From: martin bedouret Date: Mon, 25 Nov 2019 13:39:20 -0300 Subject: [PATCH 5/6] initial version --- src/analytics.js | 8 -------- src/cordova-util.js | 15 +++++++++++---- src/index.js | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/analytics.js b/src/analytics.js index c960365c7..5bcaabbed 100644 --- a/src/analytics.js +++ b/src/analytics.js @@ -22,12 +22,4 @@ const gaMiddleware = createMiddleware(eventsMap, ga, { offlineStorage }); -if (isCordova()) { - try { - onCordovaReady(window.ga.startTrackerWithId('UA-152065055-1', 20)); - } catch (err) { - console.log(err.message); - } -} - export default gaMiddleware; diff --git a/src/cordova-util.js b/src/cordova-util.js index 90a0ae470..59f3736ed 100644 --- a/src/cordova-util.js +++ b/src/cordova-util.js @@ -9,14 +9,21 @@ export const initCordovaPlugins = () => { function onDeviceReady() { console.log('now cordova is ready '); + if (isCordova()) { + try { + window.ga.startTrackerWithId('UA-152065055-1', 20); + } catch (err) { + console.log(err.message); + } + } } export const cvaTrackEvent = (category, action, label) => { try { - if (window.ga) { - window.ga.trackEvent(category, action, label); - } - } catch (err) {} + window.ga.trackEvent(category, action, label); + } catch (err) { + console.log(err.message); + } }; export const writeCvaFile = async (name, blob) => { diff --git a/src/index.js b/src/index.js index f282b709f..36551fbe4 100644 --- a/src/index.js +++ b/src/index.js @@ -37,7 +37,7 @@ const renderApp = () => { ); }; -isCordova() ? onCordovaReady(renderApp) : renderApp(); if (isCordova()) { initCordovaPlugins(); } +isCordova() ? onCordovaReady(renderApp) : renderApp(); From 679061d2af174803c360cf4ccac4853793706060 Mon Sep 17 00:00:00 2001 From: martin bedouret Date: Mon, 25 Nov 2019 16:23:36 -0300 Subject: [PATCH 6/6] debug --- src/providers/SpeechProvider/tts.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/providers/SpeechProvider/tts.js b/src/providers/SpeechProvider/tts.js index 1da570325..ca190e87c 100644 --- a/src/providers/SpeechProvider/tts.js +++ b/src/providers/SpeechProvider/tts.js @@ -49,7 +49,9 @@ const tts = { let voices = {}; try { voices = synth.getVoices(); - } catch (err) {} + } catch (err) { + console.log(err.message); + } // On Cordova, voice results are under `._list` return voices._list || voices; },