This repository has been archived by the owner on Mar 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX - Google Analytics Signed-off-by: RaenonX <[email protected]>
- Loading branch information
Showing
8 changed files
with
73 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,72 @@ | ||
import ReactGA from 'react-ga'; | ||
|
||
/** | ||
* Google Analytics custom event category. | ||
*/ | ||
export class GACategory { | ||
static APP_ACTION = 'App action' | ||
} | ||
|
||
/** | ||
* Google Analytics custom event action. | ||
* Google Analytics custom event name. | ||
*/ | ||
export class GAAction { | ||
static SWITCH_LANG = 'Switch Language' | ||
export class GAEvent { | ||
static LANG_CHANGE = 'lang_change'; | ||
static LOGIN = 'login'; | ||
static PAGE_VIEW = 'page_view'; | ||
} | ||
|
||
/** | ||
* Class for sending custom GA event | ||
* Class for sending custom GA events. | ||
*/ | ||
export class GAEvent { | ||
export class GoogleAnalytics { | ||
/** | ||
* Record the event of switching the language. | ||
* | ||
* @param {string} oldLang old language | ||
* @param {string} newLang new language | ||
*/ | ||
static languageChange(newLang: string) { | ||
ReactGA.event({ | ||
category: GACategory.APP_ACTION, | ||
action: GAAction.SWITCH_LANG, | ||
label: newLang, | ||
nonInteraction: false, | ||
}); | ||
static languageChange(oldLang: string, newLang: string) { | ||
GoogleAnalytics.sendEvent( | ||
GAEvent.LANG_CHANGE, | ||
{ | ||
'old': oldLang, | ||
'new': newLang, | ||
}, | ||
); | ||
} | ||
|
||
/** | ||
* Record the event of an user logged in. | ||
* | ||
* @param {string} method method used for login | ||
* @param {boolean} success if the login succeed | ||
*/ | ||
static login(method: string = 'Google', success: boolean = true) { | ||
GoogleAnalytics.sendEvent( | ||
GAEvent.LOGIN, | ||
{ | ||
'method': method, | ||
'success': success, | ||
}, | ||
); | ||
} | ||
|
||
/** | ||
* Record the event of a page view. | ||
* | ||
* @param {Location} location location object | ||
*/ | ||
static pageView(location: Location) { | ||
GoogleAnalytics.sendEvent( | ||
GAEvent.PAGE_VIEW, | ||
{ | ||
'page_location': location.href, | ||
'page_title': document.title, | ||
'page_path': location.pathname, | ||
}, | ||
); | ||
} | ||
|
||
/** | ||
* Send a Google Analytics event via gtag.js. | ||
* | ||
* @param {string} eventName name of the event | ||
* @param {Object} parameters parameters of the event | ||
*/ | ||
private static sendEvent(eventName: string, parameters: Object) { | ||
// @ts-ignore | ||
window.gtag('event', eventName, parameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters