UMengRecordTool.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // UMengRecordTool.h
  3. // MSYOUPAI
  4. //
  5. // Created by xiaohaoran on 2022/4/12.
  6. // Copyright © 2022 MS. All rights reserved.
  7. //
  8. #import "UMengRecordTool.h"
  9. @implementation UMengRecordTool
  10. /**
  11. @ 页面统计 - 进入
  12. */
  13. + (void)umengEnterViewWithName:(NSString *)name
  14. {
  15. [MobClick beginLogPageView:name];
  16. }
  17. /**
  18. @ 页面统计 - 退出
  19. */
  20. + (void)umengOutViewWithName:(NSString *)name
  21. {
  22. [MobClick endLogPageView:name];
  23. }
  24. /**
  25. @ 计数事件统计
  26. */
  27. + (void)umengEventCountWithId:(NSString *)eventId
  28. {
  29. [MobClick event:eventId];
  30. }
  31. /**
  32. @ 计算事件统计
  33. */
  34. + (void)umengEventCalculatWithId:(NSString *)eventId attributes:(NSDictionary *)attributes number:(nullable id)number
  35. {
  36. NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionaryWithDictionary:attributes];
  37. if (number) {
  38. NSString *numberKey = @"__ct__";
  39. [mutableDictionary setObject:[number stringValue] forKey:numberKey];
  40. }
  41. [MobClick event:eventId attributes:mutableDictionary];
  42. }
  43. /**
  44. @ ScrollView 已滚动/浏览的百分比
  45. */
  46. + (void)umengEventScrollViewWithId:(NSString *)eventId attributes:(NSDictionary *)attributes scrollview:(UIScrollView *)scrollview isVertical:(BOOL)isVertical
  47. {
  48. NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionaryWithDictionary:attributes];
  49. CGFloat x = scrollview.contentOffset.x;
  50. CGFloat y = scrollview.contentOffset.y;
  51. CGFloat width = scrollview.contentSize.width;
  52. CGFloat height = scrollview.contentSize.height;
  53. CGFloat superVWidth = scrollview.superview.frame.size.width;
  54. CGFloat superVHeight = scrollview.superview.frame.size.height;
  55. if (isVertical) { //竖直
  56. int yInt;
  57. if (height <= superVHeight)
  58. {
  59. yInt = 100;
  60. }else
  61. {
  62. yInt = ((y+superVHeight)/height) *100;
  63. }
  64. NSString *numberKey = @"__ct__";
  65. [mutableDictionary setObject:[NSString stringWithFormat:@"%d",yInt] forKey:numberKey];
  66. }else{
  67. int xInt;
  68. if (width <= superVWidth)
  69. {
  70. xInt = 100;
  71. }else{
  72. xInt = ((x+superVWidth)/width) *100;
  73. }
  74. NSString *numberKey = @"__ct__";
  75. [mutableDictionary setObject:[NSString stringWithFormat:@"%d",xInt] forKey:numberKey];
  76. }
  77. [MobClick event:eventId attributes:mutableDictionary];
  78. }
  79. @end