Skip to content

Commit

Permalink
update AnalyticsProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
salahamassi committed May 28, 2024
1 parent 008e0b4 commit 5891fef
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 87 deletions.
165 changes: 81 additions & 84 deletions lib/core/app_analytics_providers/firebase_analytics_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ class FirebaseAnalyticsProvider extends AnalyticsProvider {

@override
void logEvent(AnalyticsEvent event) {
if (event.key != null) {
final String eventKey = event.key!.toLowerCase().replaceAll(' ', '_');
_firebaseAnalytics.logEvent(
name: eventKey,
parameters: event.params,
);
}
if (event.key == null) return;
_firebaseAnalytics.logEvent(
name: event.key!,
parameters: event.params,
);
}

@override
Expand All @@ -30,163 +28,162 @@ class FirebaseAnalyticsProvider extends AnalyticsProvider {
}

@override
void logBeginTutorial() {
void logBeginTutorial(AnalyticsEvent event) {
_firebaseAnalytics.logTutorialBegin();
}

@override
void logCompleteTutorial() {
void logCompleteTutorial(AnalyticsEvent event) {
_firebaseAnalytics.logTutorialComplete();
}

@override
void logSignedIn(UserSignedIn event) {
_firebaseAnalytics.setUserId(id: event.id.toString());
_firebaseAnalytics.logLogin(loginMethod: event.loginMethod);
void logSignedIn(AnalyticsEvent event, UserSignedIn data) {
setUserId(data.id);
_firebaseAnalytics.logLogin(loginMethod: data.loginMethod);
}

@override
void logSignedUp(UserSignedUp event) {
_firebaseAnalytics.setUserId(id: event.id.toString());
_firebaseAnalytics.logSignUp(signUpMethod: event.signupMethod);
void logSignedUp(AnalyticsEvent event, UserSignedUp data) {
setUserId(data.id);
_firebaseAnalytics.logSignUp(signUpMethod: data.signupMethod);
}

@override
void updateProfile(UserUpdateProfile event) {
_firebaseAnalytics.setUserProperty(name: 'name', value: event.name);
_firebaseAnalytics.setUserProperty(name: 'mobile', value: event.mobile);
_firebaseAnalytics.setUserProperty(name: 'email', value: event.email);
_firebaseAnalytics.setUserProperty(name: 'dob', value: event.dob);
_firebaseAnalytics.setUserProperty(name: 'gender', value: event.gender);
_firebaseAnalytics.setUserProperty(name: 'country', value: event.country);
_firebaseAnalytics.setUserProperty(name: 'city', value: event.city);
_firebaseAnalytics.setUserProperty(
name: 'age', value: event.age.toString());
event.customAttributes.forEach(_sendCustomAttributes);
void updateProfile(AnalyticsEvent event, UserUpdateProfile data) {
_firebaseAnalytics.setUserProperty(name: 'name', value: data.name);
_firebaseAnalytics.setUserProperty(name: 'mobile', value: data.mobile);
_firebaseAnalytics.setUserProperty(name: 'email', value: data.email);
_firebaseAnalytics.setUserProperty(name: 'dob', value: data.dob);
_firebaseAnalytics.setUserProperty(name: 'gender', value: data.gender);
_firebaseAnalytics.setUserProperty(name: 'country', value: data.country);
_firebaseAnalytics.setUserProperty(name: 'city', value: data.city);
_firebaseAnalytics.setUserProperty(name: 'age', value: data.age.toString());
data.customAttributes.forEach(_sendCustomAttributes);
}

@override
void logViewItemList(UserViewedItemList event) {
void logViewItemList(AnalyticsEvent event, UserViewedItemList data) {
_firebaseAnalytics.logViewItemList(
items: event.items?.map((item) => item.analyticsEventItem).toList(),
itemListId: event.itemListId,
itemListName: event.itemListName,
items: data.items?.map((item) => item.analyticsEventItem).toList(),
itemListId: data.itemListId,
itemListName: data.itemListName,
);
}

@override
void logViewItem(UserViewItem event) {
void logViewItem(AnalyticsEvent event, UserViewItem data) {
_firebaseAnalytics.logViewItem(
currency: event.currency,
value: event.value,
items: event.items?.map((item) => item.analyticsEventItem).toList(),
currency: data.currency,
value: data.value,
items: data.items?.map((item) => item.analyticsEventItem).toList(),
);
}

@override
void logSelectItem(UserSelectItem event) {
void logSelectItem(AnalyticsEvent event, UserSelectItem data) {
_firebaseAnalytics.logSelectItem(
itemListId: event.itemListId,
itemListName: event.itemListName,
items: event.items.map((item) => item.analyticsEventItem).toList(),
itemListId: data.itemListId,
itemListName: data.itemListName,
items: data.items.map((item) => item.analyticsEventItem).toList(),
);
}

@override
void logViewPromotion(UserViewPromotion event) {
void logViewPromotion(AnalyticsEvent event, UserViewPromotion data) {
_firebaseAnalytics.logViewPromotion(
promotionId: event.promotionId,
promotionName: event.promotionName,
creativeName: event.creativeName,
creativeSlot: event.creativeSlot,
items: event.items?.map((item) => item.analyticsEventItem).toList(),
promotionId: data.promotionId,
promotionName: data.promotionName,
creativeName: data.creativeName,
creativeSlot: data.creativeSlot,
items: data.items?.map((item) => item.analyticsEventItem).toList(),
);
}

@override
void logSelectPromotion(UserSelectPromotion event) {
void logSelectPromotion(AnalyticsEvent event, UserSelectPromotion data) {
_firebaseAnalytics.logSelectPromotion(
promotionId: event.promotionId,
promotionName: event.promotionName,
creativeName: event.creativeName,
creativeSlot: event.creativeSlot,
items: event.items?.map((item) => item.analyticsEventItem).toList(),
promotionId: data.promotionId,
promotionName: data.promotionName,
creativeName: data.creativeName,
creativeSlot: data.creativeSlot,
items: data.items?.map((item) => item.analyticsEventItem).toList(),
);
}

@override
void logAddToCart(UserAddedToCart event) {
void logAddToCart(AnalyticsEvent event, UserAddedToCart data) {
_firebaseAnalytics.logAddToCart(
items: event.items.map((item) => item.analyticsEventItem).toList(),
value: event.value,
currency: event.currency,
items: data.items.map((item) => item.analyticsEventItem).toList(),
value: data.value,
currency: data.currency,
);
}

@override
void logRemoveFromCart(UserRemovedFromCart event) {
void logRemoveFromCart(AnalyticsEvent event, UserRemovedFromCart data) {
_firebaseAnalytics.logRemoveFromCart(
items: event.items.map((item) => item.analyticsEventItem).toList(),
value: event.value,
currency: event.currency,
items: data.items.map((item) => item.analyticsEventItem).toList(),
value: data.value,
currency: data.currency,
);
}

@override
void logBeginCheckout(UserBeginCheckout event) {
void logBeginCheckout(AnalyticsEvent event, UserBeginCheckout data) {
_firebaseAnalytics.logBeginCheckout(
value: event.value,
currency: event.currency,
items: event.items.map((item) => item.analyticsEventItem).toList(),
value: data.value,
currency: data.currency,
items: data.items.map((item) => item.analyticsEventItem).toList(),
);
}

@override
void logMadePurchase(UserMadePurchase event) {
void logMadePurchase(AnalyticsEvent event, UserMadePurchase data) {
_firebaseAnalytics.logPurchase(
transactionId: event.transactionId,
value: event.value,
tax: event.tax,
currency: event.currency,
coupon: event.coupon,
transactionId: data.transactionId,
value: data.value,
tax: data.tax,
currency: data.currency,
coupon: data.coupon,
items:
event.items.map((EventItem item) => item.analyticsEventItem).toList(),
data.items.map((EventItem item) => item.analyticsEventItem).toList(),
);
}

@override
void logRefundOrder(UserRefundOrder event) {
void logRefundOrder(AnalyticsEvent event, UserRefundOrder data) {
_firebaseAnalytics.logRefund(
transactionId: event.transactionId,
value: event.value,
tax: event.tax,
currency: event.currency,
coupon: event.coupon,
transactionId: data.transactionId,
value: data.value,
tax: data.tax,
currency: data.currency,
coupon: data.coupon,
items:
event.items.map((EventItem item) => item.analyticsEventItem).toList(),
data.items.map((EventItem item) => item.analyticsEventItem).toList(),
);
}

@override
void logSearch(UserSearch event) {
void logSearch(AnalyticsEvent event, UserSearch data) {
_firebaseAnalytics.logSearch(
searchTerm: event.searchTerm,
searchTerm: data.searchTerm,
);
}

@override
void logShareContent(UserShareContent event) {
void logShareContent(AnalyticsEvent event, UserShareContent data) {
_firebaseAnalytics.logShare(
contentType: event.contentType,
itemId: event.itemId,
method: event.method ?? 'unknown',
contentType: data.contentType,
itemId: data.itemId,
method: data.method ?? 'unknown',
);
}

@override
void logViewSearchResults(UserViewSearchResult event) {
void logViewSearchResults(AnalyticsEvent event, UserViewSearchResult data) {
_firebaseAnalytics.logViewSearchResults(
searchTerm: event.searchTerm,
searchTerm: data.searchTerm,
);
}

Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ packages:
dependency: "direct main"
description:
name: bond_app_analytics
sha256: d695548d812271fdb31e42dd2d10c1cd3c24f0e51201533bfb2e46d2bc698a66
sha256: "816a07b27c82ec1524f365e2389f9c058a7216a55c04b60caa38b3d07272f024"
url: "https://pub.dev"
source: hosted
version: "0.0.1+2"
version: "0.0.1+3"
bond_cache:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies:
bond_cache: ^0.0.2
bond_form: ^0.0.1+10
bond_form_riverpod: ^0.0.1+3
bond_app_analytics: ^0.0.1
bond_app_analytics: ^0.0.1+3
bond_notifications: ^0.0.1


Expand Down

0 comments on commit 5891fef

Please sign in to comment.