Initial commit: StackPilot - Docker stack builder with 186 apps, compose analyser, analytics
This commit is contained in:
37
src/utils/analytics.js
Normal file
37
src/utils/analytics.js
Normal file
@@ -0,0 +1,37 @@
|
||||
// Lightweight analytics — tracks app selection popularity
|
||||
// Uses a simple JSON API. Replace the URL with your own backend.
|
||||
|
||||
const ANALYTICS_URL = '/api/analytics';
|
||||
|
||||
/**
|
||||
* Record which apps were included in a downloaded bundle.
|
||||
* Fires on download — not on selection (avoids noise).
|
||||
*/
|
||||
export async function trackDownload(selectedAppIds) {
|
||||
try {
|
||||
await fetch(`${ANALYTICS_URL}/download`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
apps: selectedAppIds,
|
||||
timestamp: new Date().toISOString(),
|
||||
}),
|
||||
});
|
||||
} catch (e) {
|
||||
// Silent fail — analytics should never break the app
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch popularity stats (app download counts).
|
||||
* Returns: { [appId]: count }
|
||||
*/
|
||||
export async function fetchPopularity() {
|
||||
try {
|
||||
const res = await fetch(`${ANALYTICS_URL}/popularity`);
|
||||
if (res.ok) return await res.json();
|
||||
} catch (e) {
|
||||
// Silent fail
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user