I'm trying to use the Google API Package (Pub Dev) but with no lucky to undestand how to connect it in my Flutter Project.
I'm trying to use the Google API Package (Pub Dev) but with no lucky to undestand how to connect it in my Flutter Project.
Hi you need to use this package https://pub.dev/packages/firebase_analytics
you can find a sample App using analytics following this link
Google Analytics works on mobile Apps too and provides all sorts of useful features check this link for more info
You need to add dependency for analytics in android/app/build.gradle, implementation 'com.google.firebase:firebase-analytics'. If you need to log events then you might want to use the package https://pub.dev/packages/firebase_analytics. Otherwise just adding above dependency is sufficient.
If you are looking for a simple approach more than using a package, then you can follow the below solution.
Add the following app.js in web/ directory
// file: /web/app.js
function sendNavigation(location) {
// Replace UA-XXXXXXXXX-X with Google Analytics ID
gtag('config', 'UA-XXXXXXXXX-X', { page_path: location });
}
Add the script into web/index.html by adding
<head>
<!--...-->
<script src="app.js" defer></script>
</head>
Now, you can simply call
js.context.callMethod('sendNavigation', ['routePath']);
when the user navigates to the page in dart file.
You can learn more about this from a blog I wrote - link