Skip to content

Nt/plausible user agent #2984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/providers/plausible/plausible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const recordPlausibleEvent = async (urlPath: string, eventName?: string):
force: true,
};

const userAgent = await DeviceInfo.getUserAgent();
const userAgent = getEcencyUserAgent();
const res = await plausibleApi.post(PATH_EVENT_API, payload, {
headers: { 'User-Agent': userAgent },
});
Expand Down Expand Up @@ -116,3 +116,20 @@ export const fetchPostStatsByDimension = async <T>(

return postStats;
};


const getEcencyUserAgent = () => {
const appName = DeviceInfo.getApplicationName();
const appVersion = DeviceInfo.getVersion();
const systemName = Platform.OS === 'ios' ? 'iOS' : 'Android';
const systemVersion = DeviceInfo.getSystemVersion();
const deviceModel = DeviceInfo.getModel();

//This combination ensures event appear as Mobile App with specific version installed
//The last part starting from Version/4.0 is essential for plausoible to record event as Mobile App, no other combination works
const userAgent = `${appName}/${appVersion} (${systemName} ${systemVersion}; ${deviceModel}) Version/4.0 Chrome/${appVersion} Mobile`;

console.log("Plausible User Agent", userAgent);

return userAgent
}