-
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.
* Update Freesound keys and GA * Increase API response page size * 1.3.6
- Loading branch information
Showing
16 changed files
with
275 additions
and
96 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
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
export {}; | ||
declare global { | ||
interface Window { | ||
dataLayer: any; | ||
} | ||
} | ||
|
||
const { app } = require('electron').remote; | ||
const { JSONStorage } = require('node-localstorage'); | ||
const nodeStorage = new JSONStorage(app.getPath('userData')); | ||
const remote = window.require('electron').remote; | ||
const env = remote.getGlobal('process').env; | ||
|
||
// const measurementId = process.env.GA4_MEASUREMENT_ID ?? env.GA4_MEASUREMENT_ID; | ||
const measurementId = 'G-HTY5MME75G'; | ||
const apiSecret = 'Xb8Rtz75T52vgGyQ1H-d2g'; | ||
const gtagScriptUrl = `https://www.googletagmanager.com/gtag/js?id=${measurementId}`; | ||
let GA_LOCAL_STORAGE_KEY = 'ga:clientId'; | ||
|
||
function gtag() { | ||
window.dataLayer.push(arguments); | ||
} | ||
|
||
const loadScript = async (url: string) => { | ||
try { | ||
const response = await fetch(url); | ||
const script = await response.text(); | ||
eval(script); | ||
} catch (error) { | ||
console.warn(`Can't load script ${url} because of the error: ${error.msg}`); | ||
} | ||
}; | ||
|
||
const gtagGetPromisify = (propertyName: string): Promise<string> => { | ||
return new Promise((resolve, reject) => { | ||
// @ts-ignore | ||
gtag('get', measurementId, propertyName, (value) => { | ||
resolve(value); | ||
}); | ||
}); | ||
}; | ||
|
||
// Get clientId from localStorage | ||
// or get it from gtag() and save it to localStorage | ||
const getClientId = async () => { | ||
const clientIdFromLocalStorage = nodeStorage.getItem(GA_LOCAL_STORAGE_KEY); | ||
|
||
if (clientIdFromLocalStorage) return clientIdFromLocalStorage; | ||
else { | ||
const clientId = await gtagGetPromisify('client_id'); | ||
nodeStorage.setItem(GA_LOCAL_STORAGE_KEY, clientId); | ||
return clientId; | ||
} | ||
}; | ||
|
||
const register = async () => { | ||
await loadScript(gtagScriptUrl); | ||
|
||
window.dataLayer = window.dataLayer || []; | ||
// console.log('window.dataLayer', window.dataLayer); | ||
|
||
if (!nodeStorage) | ||
return Promise.reject(`Can't start GA4. LocalStorage isn't available`); | ||
|
||
// @ts-ignore | ||
gtag('js', new Date()); | ||
|
||
const clientId = await getClientId(); | ||
|
||
// Use localStorage instead of cookies, since 🍪 aren't available on desktop app. | ||
// https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#using_localstorage_to_store_the_client_id | ||
const options = { | ||
storage: 'none', | ||
clientId, | ||
}; | ||
// @ts-ignore | ||
gtag('config', measurementId, options); | ||
|
||
// Disable file protocol checking | ||
// @ts-ignore | ||
gtag('set', { checkProtocolTask: null }); | ||
// @ts-ignore | ||
gtag('set', { checkStorageTask: null }); // Disable cookie storage checking | ||
// @ts-ignore | ||
gtag('set', { historyImportTask: null }); // Disable history checking (requires reading from cookies) | ||
}; | ||
|
||
const sendEvent = async (name: string, params: unknown) => { | ||
const clientId = await getClientId(); | ||
|
||
try { | ||
await fetch( | ||
`https://www.google-analytics.com/mp/collect?measurement_id=${measurementId}&api_secret=${apiSecret}`, | ||
{ | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
client_id: clientId, | ||
user_id: 'dev_user', | ||
events: [ | ||
{ | ||
name: name, | ||
params: params, | ||
}, | ||
], | ||
}), | ||
} | ||
); | ||
} catch (error) { | ||
console.warn('Error sending event to GA4: ', error.message); | ||
} | ||
}; | ||
|
||
export default { | ||
register, | ||
sendEvent, | ||
}; |
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,37 +1,51 @@ | ||
import { app } from 'electron'; | ||
import ua from 'universal-analytics'; | ||
// import ua from 'universal-analytics'; | ||
|
||
// import Analytics from 'electron-google-analytics'; | ||
import userId from '../../main/userId'; | ||
|
||
const GA_API_KEY = 'UA-173935505-1'; | ||
const appName = app.getName(); | ||
const appVersion = app.getVersion(); | ||
// const GA_API_KEY = 'UA-173935505-1'; | ||
// const GA_API_KEY = 'G-15X5TFP4CY'; | ||
// const appName = app.getName(); | ||
// const appVersion = app.getVersion(); | ||
|
||
const gaApiKey = process.env.GA_API_KEY || GA_API_KEY || ''; | ||
const visitor = ua(gaApiKey, userId); | ||
// const gaApiKey = process.env.GA_API_KEY || GA_API_KEY || ''; | ||
// const visitor = ua(gaApiKey, userId); | ||
// Allows filtering by the 'Application?' field in GA | ||
// visitor.set('ds', 'app'); | ||
visitor.set('uid', userId); | ||
// visitor.set('uid', userId); | ||
|
||
// console.log('gaApiKey', gaApiKey); | ||
|
||
// console.log('userId', userId); | ||
|
||
// const analytics = new Analytics(GA_API_KEY); | ||
// analytics.set('uid', userId); | ||
|
||
// analytics.pageview('http://example.com', '/home', 'Example'); | ||
|
||
// visitor.pageview("/").send(); | ||
|
||
function trackEvent(category, action, label, value) { | ||
visitor | ||
.event({ | ||
ec: category, | ||
ea: action, | ||
el: label, | ||
ev: value, | ||
}) | ||
.send(); | ||
// visitor | ||
// .event({ | ||
// ec: category, | ||
// ea: action, | ||
// el: label, | ||
// ev: value, | ||
// }) | ||
// .send(); | ||
} | ||
|
||
// trackEvent('Test Event', 'test action'); | ||
visitor.event('Event Category', 'Event Action').send(); | ||
// visitor.event('Event Category', 'Event Action').send(); | ||
|
||
function trackScreenView(screenName: string) { | ||
visitor.screenview(screenName, appName, appVersion).send(); | ||
// visitor.screenview(screenName, appName, appVersion).send(); | ||
} | ||
|
||
function trackSessionTiming(time: string) { | ||
visitor.timing('User interaction', 'User Session Time', time).send(); | ||
// visitor.timing('User interaction', 'User Session Time', time).send(); | ||
} | ||
|
||
export default { trackEvent, trackScreenView, trackSessionTiming }; | ||
export default { trackEvent, trackScreenView, trackSessionTiming, analytics }; |
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
Oops, something went wrong.