Skip to content

Commit

Permalink
Implement analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
Egor committed Nov 28, 2021
1 parent 43a52e6 commit e90b296
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 42 deletions.
25 changes: 20 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var electron = require("electron");
var ua = require("universal-analytics");
var Analytics = require("electron-google-analytics");

const { menubar } = require("menubar");
var ipcMain = require("electron").ipcMain;
Expand Down Expand Up @@ -88,13 +88,28 @@ var defaultMenu = [
];

mb.on("ready", function ready() {
console.info("App version", mb.app.getVersion());
console.info("Main process is ready, continue...");
console.info("Debug:", !!process.env.npm_config_debug);

var visitor = ua("UA-92232645-1");

visitor.set("appVersion", mb.app.getVersion());
visitor.event("App cycle", "OnReady").send();
const analytics = new Analytics.default("UA-92232645-1");

analytics.set("appName", "MenuTube");
analytics.set("appVersion", mb.app.getVersion());

analytics
.event("AppCycle", "OnReady", {
evLabel: "appVersion",
evValue: mb.app.getVersion(),
})
.then((data) => {
return ipcMain.on("navigatedPage", function (event, e) {
analytics.pageview(e.host, e.url, e.title, data.clientID).then(() => {
console.log("Page view event sent: " + e.url);
});
});
})
.catch(console.info);

/*
* Set app menu to be able to use copy and paste shortcuts
Expand Down
98 changes: 63 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "DEBUG=true electron .",
"dev": "npm start && npm run --debug",
"dist": "electron-builder",
"dist:debug": "DEBUG=electron-builder electron-builder --dir",
"prettier": "prettier --write ."
Expand Down Expand Up @@ -40,7 +39,7 @@
"bulma": "^0.3.2",
"electron-config": "^0.2.1",
"font-awesome": "^4.7.0",
"universal-analytics": "^0.5.1",
"electron-google-analytics": "^1.0.2",
"menubar": "^9.0.1"
},
"devDependencies": {
Expand Down
15 changes: 15 additions & 0 deletions src/wvHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,23 @@ document.addEventListener = () => {
};
})();

var currentTitle = "";

_newListener("DOMContentLoaded", () => {
observeDOM(document.body, function (m) {
// Sending only video urls
if (
window.location.pathname.includes("watch") &&
window.document.title !== currentTitle
) {
ipcRenderer.send("navigatedPage", {
host: window.location.host,
url: window.location.pathname + window.location.search,
title: window.document.title,
});
currentTitle = window.document.title;
}

const _check = (v) => v !== null && v !== undefined;
const ad = [...document.querySelectorAll(".ad-showing")][0];
if (_check(ad)) {
Expand Down

0 comments on commit e90b296

Please sign in to comment.