Skip to content

Commit

Permalink
configure google analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
immadisairaj committed Mar 7, 2022
1 parent 9b26bdb commit 3085912
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/router/site_router_delegate.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import 'package:flutter/material.dart';
import 'package:js/js.dart';
import 'package:website/router/site_route_path.dart';
import 'package:website/router/site_transition_delegate.dart';
import 'package:website/screens/about/about.dart';
import 'package:website/screens/home/home.dart';
import 'package:website/screens/splash_screen/splash_screen.dart';
import 'package:website/screens/unknown/unknown.dart';

// use send navigation js events from web/app.js
@JS('sendNavigation')
external void sendNavigation(String routeName);

class SiteRouterDelegate extends RouterDelegate<SiteRoutePath>
with ChangeNotifier, PopNavigatorRouterDelegateMixin<SiteRoutePath> {
@override
Expand Down Expand Up @@ -77,15 +82,19 @@ class SiteRouterDelegate extends RouterDelegate<SiteRoutePath>
@override
SiteRoutePath get currentConfiguration {
if (_show404) {
sendNavigation('/404');
return SiteRoutePath.unknown();
}

if (_isHome) {
sendNavigation('/home');
return SiteRoutePath.home();
}
if (_isAbout) {
sendNavigation('/about');
return SiteRoutePath.about();
}
sendNavigation('/');
return SiteRoutePath.splash();
}

Expand Down
4 changes: 4 additions & 0 deletions web/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function sendNavigation(location) {
// Replace UA-XXXXXXXXX-X with Google Analytics ID
gtag('config', 'UA-168944360-2', { page_path: location });
}
6 changes: 4 additions & 2 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
gtag('js', new Date());

// // Replace UA-XXXXXXXXX-X with Google Analytics ID
gtag('config', 'UA-168944360-2');
// gtag('config', 'UA-168944360-2', { send_page_view: false });
// gtag('config', 'UA-168944360-2');
gtag('config', 'UA-168944360-2', { send_page_view: false });
</script>

<title>immadisairaj</title>
<link rel="manifest" href="manifest.json">

<script src="app.js" defer></script>
</head>
<body>

Expand Down

0 comments on commit 3085912

Please sign in to comment.