Skip to content

Commit

Permalink
Feature/257 analytics tabs screen (#266)
Browse files Browse the repository at this point in the history
* Change screen on Firebase Analytics on explore tab change

* Change screen on Firebase Analytics on main tab change

* Regenerated pod lockfile

* Add prefixes to analytics tab events

* Regenerated pod lockfile

---------

Co-authored-by: kackogut <kackogut@users.noreply.github.com>
  • Loading branch information
kackogut and kackogut authored Mar 4, 2024
1 parent ff99a17 commit 3a9b9a9
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/services/analytics.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:logging/logging.dart';

import 'package:nowu/models/Action.dart';
import 'package:nowu/models/Learning.dart';
import 'package:nowu/models/article.dart';
Expand All @@ -19,6 +18,10 @@ class AnalyticsService {
await _analytics.setUserId(id: userId);
}

Future<void> setCustomRoute(String route) async {
await _analytics.logScreenView(screenName: route);
}

Future<void> logActionEvent(
Action action,
ActionEvent event,
Expand Down
13 changes: 9 additions & 4 deletions lib/ui/views/explore/explore_page_view.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:nowu/assets/constants.dart';
import 'package:flutter/material.dart';
import 'package:nowu/assets/constants.dart';
import 'package:nowu/ui/views/explore/tabs/explore_all_tab.dart';
import 'package:nowu/ui/views/explore/tabs/explore_campaign_tab.dart';
import 'package:nowu/ui/views/explore/tabs/explore_news_article_tab.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked/stacked_annotations.dart';

import 'explore_page_viewmodel.dart';
import 'explore_page_view.form.dart';
import 'explore_page_viewmodel.dart';
import 'tabs/explore_action_tab.dart';
import 'tabs/explore_learning_resource_tab.dart';

Expand Down Expand Up @@ -106,13 +106,15 @@ class ExploreTabs extends StatefulWidget {

class _ExploreTabsState extends State<ExploreTabs>
with TickerProviderStateMixin {
ExplorePageViewModel? _viewModel;
TabController? _tabController;

@override
void initState() {
super.initState();
_tabController =
TabController(length: ExploreTabKey.values.length, vsync: this);
_viewModel = widget.viewModel;
}

@override
Expand Down Expand Up @@ -154,9 +156,12 @@ class _ExploreTabsState extends State<ExploreTabs>
.map(
(tab) => getTabData(tab).child(
widget.viewModel,
(ExploreTabKey tab) => _tabController?.animateTo(tab.index),
(ExploreTabKey tab) {
_viewModel?.onTabChanged(tab);
_tabController?.animateTo(tab.index);
},
),
)
)
.toList(),
),
);
Expand Down
7 changes: 7 additions & 0 deletions lib/ui/views/explore/explore_page_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import 'package:nowu/utils/new_since.dart';
import 'package:stacked/stacked.dart';
import 'package:tuple/tuple.dart';

import '../../../services/analytics.dart';
import '../../../services/model/search/search_response.dart';
import '../../paging/paging_state.dart';
import 'explore_page_view.dart';
import 'explore_page_view.form.dart';

enum ExploreSectionType {
Expand Down Expand Up @@ -45,6 +47,7 @@ class ExplorePageViewModel extends FormViewModel {
final _causesService = locator<CausesService>();
final _searchService = locator<SearchService>();
final _bottomSheetService = locator<BottomSheetService>();
final _analyticsService = locator<AnalyticsService>();

BaseResourceSearchFilter searchFilter = const BaseResourceSearchFilter();

Expand Down Expand Up @@ -320,6 +323,10 @@ class ExplorePageViewModel extends FormViewModel {
bool? isCampaignComplete(ListCampaign campaign) {
return _causesService.campaignIsComplete(campaign.id);
}

void onTabChanged(ExploreTabKey tab) {
_analyticsService.setCustomRoute('explore_${tab.toString()}');
}
}

sealed class ExploreTileData {}
Expand Down
6 changes: 6 additions & 0 deletions lib/ui/views/tabs/tabs_viewmodel.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import 'package:stacked/stacked.dart';

import '../../../app/app.locator.dart';
import '../../../services/analytics.dart';

enum TabPage { Home, Explore, Menu }

class TabsViewModel extends BaseViewModel {
final _analyticsService = locator<AnalyticsService>();

TabsViewModel(TabPage? initalPage) {
if (initalPage != null) {
this.currentPage = initalPage;
Expand All @@ -12,6 +17,7 @@ class TabsViewModel extends BaseViewModel {
TabPage currentPage = TabPage.Home;

void setPage(TabPage newPage) {
_analyticsService.setCustomRoute('tab_${newPage.name}');
currentPage = newPage;
notifyListeners();
}
Expand Down
94 changes: 94 additions & 0 deletions openapi/openapi-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,81 @@ paths:
schema:
$ref: '#/components/schemas/NewsArticle'
description: ''
/new_articles/{id}/complete/:
post:
operationId: news_article_complete
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this news article.
required: true
tags:
- new_articles
security:
- tokenAuth: []
- {}
responses:
'200':
description: No response body
/news_articles/:
get:
operationId: news_articles_list
tags:
- news_articles
security:
- tokenAuth: []
- {}
responses:
'200':
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/NewsArticle'
description: ''
/news_articles/{id}/:
get:
operationId: news_articles_retrieve
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this news article.
required: true
tags:
- news_articles
security:
- tokenAuth: []
- {}
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/NewsArticle'
description: ''
/news_articles/{id}/complete/:
post:
operationId: news_article_complete_2
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this news article.
required: true
tags:
- news_articles
security:
- tokenAuth: []
- {}
responses:
'200':
description: No response body
/organisations/:
get:
operationId: organisations_list
Expand Down Expand Up @@ -850,10 +925,16 @@ components:
items:
type: integer
readOnly: true
completed_news_article_ids:
type: array
items:
type: integer
readOnly: true
required:
- completed_action_ids
- completed_campaign_ids
- completed_learning_resource_ids
- completed_news_article_ids
- id
- selected_causes_ids
Faq:
Expand Down Expand Up @@ -914,6 +995,9 @@ components:
$ref: '#/components/schemas/Cause'
release_at_timestamp:
type: integer
is_completed:
type: boolean
readOnly: true
created_at:
type: string
format: date-time
Expand Down Expand Up @@ -953,6 +1037,7 @@ components:
- causes
- created_at
- id
- is_completed
- learning_resource_type
- link
- release_at
Expand Down Expand Up @@ -1069,6 +1154,9 @@ components:
$ref: '#/components/schemas/Image'
release_at_timestamp:
type: integer
is_completed:
type: boolean
readOnly: true
created_at:
type: string
format: date-time
Expand Down Expand Up @@ -1111,6 +1199,7 @@ components:
- created_at
- header_image
- id
- is_completed
- link
- published_at
- release_at
Expand Down Expand Up @@ -1244,6 +1333,11 @@ components:
items:
type: integer
readOnly: true
completed_news_article_ids:
type: array
items:
type: integer
readOnly: true
PatchedUserProfile:
type: object
properties:
Expand Down

0 comments on commit 3a9b9a9

Please sign in to comment.