Skip to content
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

Fix plugin for web #11

Closed
wants to merge 3 commits into from
Closed
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
11 changes: 7 additions & 4 deletions lib/plausible_analytics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ class Plausible {
}

// Http Post request see https://plausible.io/docs/events-api
HttpClient client = HttpClient();
try {
HttpClient client = HttpClient();
HttpClientRequest request =
await client.postUrl(Uri.parse(serverUrl + '/api/event'));
request.headers.set('User-Agent', userAgent);
if (!kIsWeb) {
// browser adds by default this header so we should not overwrite it
request.headers.set('User-Agent', userAgent);
}
request.headers.set('Content-Type', 'application/json; charset=utf-8');
request.headers.set('X-Forwarded-For', '127.0.0.1');
Object body = {
"domain": domain,
"name": name,
Expand All @@ -61,12 +63,13 @@ class Plausible {
};
request.write(json.encode(body));
final HttpClientResponse response = await request.close();
client.close();
return response.statusCode;
} catch (e) {
if (kDebugMode) {
print(e);
}
} finally {
client.close();
}

return 1;
Expand Down