Skip to content

Commit

Permalink
Refactored submodules to simplify setup
Browse files Browse the repository at this point in the history
  • Loading branch information
goenning committed May 24, 2023
1 parent b4dd6ec commit d46e52a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 41 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.4

Refactored submodules to simplify setup

## 0.1.3

Added notice when importing `@aptabase/electron` module
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ app.whenReady().then(() => {
});
```

When tracking events from your `main` process, import the `trackEvent` from the `@aptabase/electron/main` package and call it:
When tracking events from your `main` process, import the `trackEvent` function from `@aptabase/electron/main`:

```js
import { trackEvent } from "@aptabase/electron/main";
Expand All @@ -41,18 +41,18 @@ trackEvent("connect_click"); // An event with no properties
trackEvent("play_music", { name: "Here comes the sun" }); // An event with a custom property
```

To track events from the renderer process, add this to your preload script:
To track events from the renderer process, you must first expose Aptabase within your preload script:

```js
import { exposeAptabase } from "@aptabase/electron/preload";

exposeAptabase();
```

Afterwards you can use the `trackEvent` function from the `@aptabase/electron/renderer` package:
Then you can use the `trackEvent` function from the `@aptabase/electron` package:

```js
import { trackEvent } from "@aptabase/electron/renderer";
import { trackEvent } from "@aptabase/electron";

trackEvent("connect_click"); // An event with no properties
trackEvent("play_music", { name: "Here comes the sun" }); // An event with a custom property
Expand Down
2 changes: 1 addition & 1 deletion example/src/counter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { trackEvent } from "@aptabase/electron/renderer";
import { trackEvent } from "@aptabase/electron";

export function setupCounter(element: HTMLButtonElement) {
let counter = 0;
Expand Down
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aptabase/electron",
"version": "0.1.3",
"version": "0.1.4",
"private": false,
"description": "Electron SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps",
"sideEffects": false,
Expand All @@ -16,11 +16,6 @@
"require": "./dist/main.cjs.js",
"types": "./dist/main.d.ts"
},
"./renderer": {
"import": "./dist/renderer.es.js",
"require": "./dist/renderer.cjs.js",
"types": "./dist/renderer.d.ts"
},
"./preload": {
"import": "./dist/preload.es.js",
"require": "./dist/preload.cjs.js",
Expand Down
36 changes: 31 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
export const NOTICE = `You seem to have imported something from '@aptabase/electron' which does not export anything.
- Use '@aptabase/electron/main' in your main process.
- Use '@aptabase/electron/preload' in your preload script.
- Use '@aptabase/electron/renderer' in your renderer process.`;
declare global {
interface Window {
__APTABASE__: {
trackEvent(
eventName: string,
props?: Record<string, string | number | boolean>
): void;
};
}
}

export function trackEvent(
eventName: string,
props?: Record<string, string | number | boolean>
) {
if (typeof window === "undefined") {
console.error(
"Aptabase: to track events in the main process you must import 'trackEvent' from '@aptabase/electron/main'."
);
return;
}

if (!window.__APTABASE__) {
console.error(
"Aptabase: You need to call `.exposeAptabase()` from the preload script."
);
return;
}

window.__APTABASE__.trackEvent(eventName, props);
}
24 changes: 0 additions & 24 deletions src/renderer.ts

This file was deleted.

1 change: 0 additions & 1 deletion vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default defineConfig({
index: path.resolve(__dirname, "src/index.ts"),
main: path.resolve(__dirname, "src/main.ts"),
preload: path.resolve(__dirname, "src/preload.ts"),
renderer: path.resolve(__dirname, "src/renderer.ts"),
},
name: "@aptabase/electron",
fileName: (format, entryName) => `${entryName}.${format}.js`,
Expand Down

0 comments on commit d46e52a

Please sign in to comment.