Advertisement
emanuel1109

moves - IOS - Swift - Code Snippets

Jul 25th, 2022 (edited)
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 11.33 KB | None | 0 0
  1.  // if a user is logged in when he launched the app or he finished signing up or he logged in to his account, fire this line of code, insert the userId dynamically
  2. Analytics.setUserID("123456") // insert the user id like it appears in the database
  3.  
  4. // if a user is logged in when it launched the app or he logged in to his account, fire this line of code, insert the user sub status type dynamically, if a user started his trial you can fire this line as well to reflect the change
  5. Analytics.setUserProperty("insert_user_sub_status", forName: "user_sub_status") // 'free trial', 'canceled', 'monthly', 'yearly', 'expired'
  6.  
  7. // This event fires when a user starts the sign up (after he entered his email and clicks 'sign in/sign up'), only if he doesn't have an account with this email
  8. Analytics.logEvent("sign_up_started", parameters: [
  9.   "method": "email/apple" as NSObject // the method of registration, if facebook is also an option, please include it here
  10. ])
  11.  
  12. // This event fires when a user completes the signup
  13. Analytics.logEvent("sign_up_completed", parameters: [
  14.   "method": "email/apple" as NSObject // the method of registration, if facebook is also an option, please include it here
  15. ])
  16.  
  17.  // if a user is logged in when he launched the app or he finished signing up or he logged in to his account, fire this line of code, insert the userId dynamically
  18. Analytics.setUserID("123456")
  19.  
  20. // This event fires when a user clicks to start the survey
  21. Analytics.logEvent("survey_started", parameters: [
  22.   "type": "mandatory" as NSObject // the survey on mobile is usually forced (a user cannot skip it)
  23. ])
  24.  
  25. // This event fires when a user finishes the survey
  26. Analytics.logEvent("survey_finished", parameters: [
  27.   "type": "mandatory" as NSObject, // the survey on mobile is usually forced (a user cannot skip it)
  28.   "is_instructor" : "true/false" // if he checked the 'I am instructor' box then it's true
  29. ])
  30.  
  31. // if the user checks the 'I am instructor' checkbox on the survey, save it as a user parameter
  32. Analytics.setUserProperty(is_instructor, forName: "true/false") // 'true' or 'false' depends on the answer, default value: "false"
  33.  
  34. // This event fires when a user clicks on any button that redirects to starting a free trial
  35. Analytics.logEvent("cta_clicked")
  36.  
  37. // This event fires when a user clicks to 'activate membership' if he is on a free trial or clicks on 'sign up' after his membership expired (not sure if this option is available on mobile, if it is available, please implement it)
  38. Analytics.logEvent("reactivation_initiated")
  39.  
  40. // This event fires when a user finishes to 'activate membership' after his membership expired (not sure if this option is available on mobile (meaning if your app has this feature), if it is available, please implement it like I describe below)
  41. // Prepare purchase params
  42. var purchaseParams: [String: Any] = [
  43.   AnalyticsParameterTransactionID: "T12345", // transaction id
  44.   AnalyticsParameterAffiliation: "alomoves", // insert store name region here
  45.   AnalyticsParameterCurrency: "USD", // leave static if user can only be charged with USD
  46.   AnalyticsParameterValue: 14.98, // order total (excluding tax) (the amount the user paid when he activated the plan excluding tax)
  47.   AnalyticsParameterTax: 2.58, // insert tax (if available or exist in the store)
  48.   AnalyticsParameterCoupon: "SUMMER_FUN" // if coupon was applied to the order, include it here
  49. ]
  50.  
  51. // Add items
  52. purchaseParams[AnalyticsParameterItems] = [ // an array with all products
  53.   AnalyticsParameterItemID: "membership activated - monthly/annually", // monthly or annually depends on the plan the user chose
  54.   AnalyticsParameterItemName: "membership activated - monthly/annually", // monthly or annually depends on the plan the user chose
  55.   AnalyticsParameterPrice: 9.99, // insert an actual product price. Number or a string. Don't include currency code
  56.   AnalyticsParameterQuantity: 1  // product quantity. leave static
  57. ]
  58.  
  59. // Log purchase event
  60. Analytics.logEvent(AnalyticsEventPurchase, parameters: purchaseParams) // name of the event. In this case, it always must be AnalyticsEventPurchase
  61.  
  62.  
  63. // This event fires when a user chose a payment plan, captures the payment plan chosen.
  64. Analytics.logEvent("payment_plan_chosen", parameters: [
  65.   "type": "monthly/annually" as NSObject // payment plan type
  66. ])
  67.  
  68. // This event fires after a user placed his credit card information and paid on App Store and his trial started
  69. Analytics.logEvent("trial_started", parameters: [
  70.   "name": "14 Days Trial - Annual/Monthly" as NSObject // Annual or Monthly depends on the trial he started
  71. ])
  72.  
  73. // This event fires when a user has a class opened (on page load of a class)
  74. Analytics.logEvent("class_viewed", parameters: [
  75.   "class": "insert_class_name_here" as NSObject,  // insert the class name here
  76.   "series": "insert_series_name_here" as NSObject, // insert the series name here
  77.   "difficulty": "insert_difficulty_here" as NSObject, // insert the difficulty here
  78.   "intensity": "insert_intesity_here" as NSObject, // insert the intensity here
  79.   "instructor": "insert_class_instructor_name" as NSObject // insert the instructor here    
  80. ])
  81.  
  82. // This event fires when a user has a user saved a class (added to practice)
  83. Analytics.logEvent("class_saved", parameters: [
  84.   "class": "insert_class_name_here" as NSObject,  // insert the class name here
  85.   "series": "insert_series_name_here" as NSObject, // insert the series name here
  86.   "difficulty": "insert_difficulty_here" as NSObject, // insert the difficulty here
  87.   "intensity": "insert_intesity_here" as NSObject, // insert the intensity here
  88.   "instructor": "insert_class_instructor_name" as NSObject // insert the instructor here    
  89. ])
  90.  
  91. // This event fires when a user has a series opened (on page load of a series)
  92. Analytics.logEvent("series_viewed", parameters: [
  93.   "category": "insert_category_here" as NSObject, // fitness, mindfulness, skills, yoga, set your intention
  94.   "series": "insert_series_name_here" as NSObject, // insert the series name here
  95.   "difficulty": "insert_difficulty_here" as NSObject, // insert the difficulty here
  96.   "intensity": "insert_intesity_here" as NSObject, // insert the intensity here
  97.   "instructor": "insert_class_instructor_name" as NSObject // insert the instructor here  
  98. ])
  99.  
  100. // This event fires when a user adds a series to his practice
  101. Analytics.logEvent("series_saved", parameters: [
  102.   "series": "insert_series_name_here" as NSObject, // insert the series name here
  103.   "difficulty": "insert_difficulty_here" as NSObject, // insert the difficulty here
  104.   "intensity": "insert_intesity_here" as NSObject, // insert the intensity here
  105.   "instructor": "insert_class_instructor_name" as NSObject // insert the instructor here    
  106. ])
  107.  
  108. // This event fires when a user plays the series intro video, usually the video next to the series description on the series page
  109. Analytics.logEvent("series_intro_played", parameters: [
  110.   "series": "insert_series_name_here" as NSObject, // insert the series name here
  111.   "difficulty": "insert_difficulty_here" as NSObject, // insert the difficulty here
  112.   "intensity": "insert_intesity_here" as NSObject, // insert the intensity here
  113.   "instructor": "insert_class_instructor_name" as NSObject // insert the instructor here    
  114. ])
  115.  
  116. // This event fires when a user views an instructor page (on page load of an instructor page)
  117. Analytics.logEvent("instructor_viewed", parameters: [
  118.   "instructor": "insert_instructor_name" as NSObject
  119. ])
  120.  
  121. // This event fires when a user plays a video
  122. Analytics.logEvent("video_played", parameters: [
  123.   "title": "insert_video_name_here" as NSObject, // insert video title (could be the name of the class)
  124.   "class": "insert_class_name_here" as NSObject, // insert class name  
  125.   "series": "insert_series_name_here" as NSObject, // insert the series that video is part of
  126.   "difficulty": "insert_difficulty_here" as NSObject,   // insert difficulty here
  127.   "intensity": "insert_intesity_here" as NSObject, // insert intensity here
  128.   "instructor": "insert_class_instructor_name" as NSObject  // insert instructor here  
  129. ])
  130.  
  131. // This event fires every 10 seconds when a video is being played.
  132. Analytics.logEvent("video_watched_time", parameters: [
  133.   "duration" : 10 as NSObject,// 10 seconds unless defined otherwise
  134.   "title": "insert_video_name_here" as NSObject, // insert video title (could be the name of the class)
  135.   "class": "insert_class_name_here" as NSObject, // insert class name  
  136.   "series": "insert_series_name_here" as NSObject, // insert the series that video is part of
  137.   "difficulty": "insert_difficulty_here" as NSObject,   // insert difficulty here
  138.   "intensity": "insert_intesity_here" as NSObject, // insert intensity here
  139.   "instructor": "insert_class_instructor_name" as NSObject  // insert instructor here      
  140. ])
  141.  
  142. // This event fires when a user viewed 10%, 25%, 50%, 75% and 90% of the video
  143. Analytics.logEvent("video_watched_percent", parameters: [
  144.   "percent": 10 as NSObject,// 10, 25, 50, 75, 90
  145.   "title": "insert_video_name_here" as NSObject, // insert video title (could be the name of the class)
  146.   "class": "insert_class_name_here" as NSObject, // insert class name  
  147.   "series": "insert_series_name_here" as NSObject, // insert the series that video is part of
  148.   "difficulty": "insert_difficulty_here" as NSObject,   // insert difficulty here
  149.   "intensity": "insert_intesity_here" as NSObject, // insert intensity here
  150.   "instructor": "insert_class_instructor_name" as NSObject  // insert instructor here      
  151. ])
  152.  
  153. // This event fires when a user finishes watching a video
  154. Analytics.logEvent("video_finished", parameters: [
  155.   "title": "insert_video_name_here" as NSObject, // insert video title (could be the name of the class)
  156.   "class": "insert_class_name_here" as NSObject, // insert class name  
  157.   "series": "insert_series_name_here" as NSObject, // insert the series that video is part of
  158.   "difficulty": "insert_difficulty_here" as NSObject,   // insert difficulty here
  159.   "intensity": "insert_intesity_here" as NSObject, // insert intensity here
  160.   "instructor": "insert_class_instructor_name" as NSObject  // insert instructor here  
  161. ])
  162.  
  163. // This event fires when a user filters the duration
  164. Analytics.logEvent("duration_filtered", parameters: [
  165.   "filter_value": "insert_value_chosen" as NSObject // insert the value of the filter that was chosen
  166. ])
  167.  
  168. // This event fires when a user filters the instructor
  169. Analytics.logEvent("instructor_filtered", parameters: [
  170.   "filter_value": "insert_value_chosen" as NSObject // insert the value of the filter that was chosen
  171. ])
  172.  
  173. // This event fires when a user filters the style
  174. Analytics.logEvent("style_filtered", parameters: [
  175.   "filter_value": "insert_value_chosen" as NSObject // insert the value of the filter that was chosen
  176. ])
  177.  
  178. // This event fires when a user filters the difficulty
  179. Analytics.logEvent("difficulty_filtered", parameters: [
  180.   "filter_value": "insert_value_chosen" as NSObject // insert the value of the filter that was chosen
  181. ])
  182.  
  183. // This event fires when a user filters the intensity
  184. Analytics.logEvent("intensity_filtered", parameters: [
  185.   "filter_value": "insert_value_chosen" as NSObject // insert the value of the filter that was chosen
  186. ])
  187.  
  188. // This event fires when a user uses the sort function
  189. Analytics.logEvent("sorted_by", parameters: [
  190.   "filter_value": "insert_value_chosen" as NSObject // insert the value of the filter that was chosen
  191. ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement