Let's set up a new project called analytics-tracking, as follows:
- Create a new folder so that you can store all of the project files:
mkdir analytics-tracking
cd analytics-tracking
- Perform a quick setup of the repository using the following commands:
npm init -y
echo node_modules > .gitignore
npm i -D electron
- Drop an index.html file into the project root along with a primary template, as shown in the following code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Electron Analytics</title>
</head>
<body>
</body>
</html>
- Create a main.js file in the project root with a minimal set of instructions regarding how to create a new Electron window:
const { app, BrowserWindow } = require('electron');
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
},
resizable: false
});
win.loadFile('index.html');
}
app.on('ready', createWindow);
For the sake of simplicity, we're creating a non-resizable window that's 800x600 pixels in size with Node.js integration enabled by default. Feel free to add any other settings to the code if you need them.
- Update the package.json file:
{
"name": "analytics-tracking",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"electron": "^7.1.1"
}
}
- At this point, you have a barebones setup for a new Electron project so that you're ready to perform analytics and tracking integration. You can check that everything runs as expected using the following command:
npm start
- You are going to see a blank Electron window entitled Electron Analytics, as shown in the following screenshot:
That is the expected behavior so far.
Now, you have a basic application project that you can use for analytics testing. You can copy the configuration and use it as a template for future experiments. For now, let's move on and integrate the Nucleus library into this project.