123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- //
- // ASFireBaseEventManager.m
- // westkissMob
- //
- // Created by iOS on 2024/2/22.
- //
- #import "ASFireBaseEventManager.h"
- #import <FirebaseAnalytics/FirebaseAnalytics.h>
- @interface ASFireBaseEventManager()
- @end
- @implementation ASFireBaseEventManager
- static ASFireBaseEventManager *singleClass = nil;
- + (instancetype)shareInstance{
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- singleClass = [[ASFireBaseEventManager alloc]init];
- });
- return singleClass;
- }
- - (void)addcartEventWithCur:(NSString *)cur value:(double)value items:(NSArray<NSDictionary<NSString *, NSString*> *>*)items {
- NSMutableArray *arr = [NSMutableArray array];
- for (NSDictionary<NSString *, NSString*> *dic in items) {
- NSMutableDictionary<NSString *, NSString*> *tempDic = [NSMutableDictionary dictionary];
- tempDic[kFIRParameterItemID] = dic[@"item_id"];
- tempDic[kFIRParameterItemName] = dic[@"item_name"];
- [arr addObject:tempDic];
- }
- if (cur.isEmpty || arr.count == 0 || value == 0) {
- return;
- }
- [FIRAnalytics logEventWithName:kFIREventAddToCart parameters:@{
- kFIRParameterCurrency:cur,
- kFIRParameterValue:[NSNumber numberWithDouble:value],
- kFIRParameterItems:arr,
- }];
- }
- - (void)purchaseEventWithCur:(NSString *)cur value:(double)value transaction_id:(NSString *)transaction_id item:(CartTotalsM *)carListM {
- NSString *affiliate = @"APP Store";
- #if (DEBUG)
- affiliate = @"Debug Store";
- #endif
- NSMutableArray *arr = [NSMutableArray array];
- for (CartTotalsItemsM *cartItem in carListM.items) {
- NSMutableDictionary<NSString *, NSString*> *tempDic = [NSMutableDictionary dictionary];
- tempDic[kFIRParameterItemID] = cartItem.product_id;
- tempDic[kFIRParameterItemName] = cartItem.name;
-
- [arr addObject:tempDic];
- }
- NSMutableDictionary *tempDic = [NSMutableDictionary dictionary];
- tempDic[kFIRParameterTransactionID] = transaction_id;//@"T12345";
- tempDic[kFIRParameterAffiliation] = affiliate;
- tempDic[kFIRParameterCurrency] = cur;
- double totalPay = carListM.grand_total.doubleValue;
- tempDic[kFIRParameterValue] = [NSNumber numberWithDouble:totalPay];
-
- double taxPay = carListM.tax_amount.doubleValue;
- tempDic[kFIRParameterTax] = [NSNumber numberWithDouble:taxPay];
-
- double shipPay = carListM.shipping_amount.doubleValue;
- tempDic[kFIRParameterShipping] = [NSNumber numberWithDouble:shipPay];
- tempDic[kFIRParameterCoupon] = carListM.coupon_code;
- tempDic[kFIRParameterItems] = arr;
- if (cur.isEmpty || arr.count == 0) {
- return;
- }
- [FIRAnalytics logEventWithName:kFIREventPurchase parameters:tempDic];
- }
- - (void)checkOutEventWithCur:(NSString *)cur value:(double)value items:(NSArray<NSDictionary<NSString *, NSString*> *>*)items {
- NSMutableArray *arr = [NSMutableArray array];
- for (NSDictionary<NSString *, NSString*> *dic in items) {
- NSMutableDictionary<NSString *, NSString*> *tempDic = [NSMutableDictionary dictionary];
- tempDic[kFIRParameterItemID] = dic[@"item_id"];
- tempDic[kFIRParameterItemName] = dic[@"item_name"];
- [arr addObject:tempDic];
- }
- if (cur.isEmpty || items.count == 0 || value == 0) {
- return;
- }
- [FIRAnalytics logEventWithName:kFIREventBeginCheckout parameters:@{
- kFIRParameterCurrency:cur,
- kFIRParameterValue:[NSNumber numberWithDouble:value],
- kFIRParameterItems:arr,
- }];
- }
- - (void)viewItemEventWithCur:(NSString *)cur value:(double)value items:(NSArray<NSDictionary<NSString *, NSString*> *>*)items {
- NSMutableArray *arr = [NSMutableArray array];
- for (NSDictionary<NSString *, NSString*> *dic in items) {
- NSMutableDictionary<NSString *, NSString*> *tempDic = [NSMutableDictionary dictionary];
- tempDic[kFIRParameterItemID] = dic[@"item_id"];
- tempDic[kFIRParameterItemName] = dic[@"item_name"];
- [arr addObject:tempDic];
- }
- if (cur.isEmpty || arr.count == 0 || value == 0) {
- return;
- }
-
- [FIRAnalytics logEventWithName:kFIREventViewItem parameters:@{
- kFIRParameterCurrency:cur,
- kFIRParameterValue:[NSNumber numberWithDouble:value],
- kFIRParameterItems:arr,
- }];
- }
- @end
|