|
| 1 | +import { Injectable } from '@angular/core'; |
| 2 | +import { Cordova, CordovaProperty, IonicNativePlugin, Plugin } from '@ionic-native/core'; |
| 3 | + |
| 4 | +/** |
| 5 | + * @name Analytics Firebase |
| 6 | + * @description |
| 7 | + * Google Analytics Firebase plugin for Ionic Native apps. |
| 8 | + * |
| 9 | + * @usage |
| 10 | + * ```typescript |
| 11 | + * import { AnalyticsFirebase } from '@ionic-native/analytics-firebase'; |
| 12 | + * |
| 13 | + * |
| 14 | + * constructor(private analyticsFirebase: AnalyticsFirebase) { } |
| 15 | + * |
| 16 | + * // Track an event with default events and params |
| 17 | + * const eventParams = {}; |
| 18 | + * eventParams[this.analyticsFirebase.DEFAULT_PARAMS.LEVEL] = 29; |
| 19 | + * this.analyticsFirebase.logEvent(this.analyticsFirebase.DEFAULT_EVENTS.LEVEL_UP, eventParams) |
| 20 | + * .then(() => console.log('Event successfully tracked')) |
| 21 | + * .catch(err => console.log('Error tracking event:', err)); |
| 22 | + * |
| 23 | + * // Track an event with custom events and params |
| 24 | + * const eventParams = {}; |
| 25 | + * eventParams['my-prop'] = 29; |
| 26 | + * this.analyticsFirebase.logEvent('my-event', eventParams) |
| 27 | + * .then(() => console.log('Event successfully tracked')) |
| 28 | + * .catch(err => console.log('Error tracking event:', err)); |
| 29 | + * |
| 30 | + * |
| 31 | + * // Reset analytics data |
| 32 | + * this.analyticsFirebase.resetAnalyticsData() |
| 33 | + * .then(() => console.log('Analytics data have been reset')) |
| 34 | + * .catch(err => console.log('Error resetting analytics data:', err)); |
| 35 | + * |
| 36 | + * |
| 37 | + * // Track a screen view |
| 38 | + * this.analyticsFirebase.setCurrentScreen('Home') |
| 39 | + * .then(() => console.log('View successfully tracked')) |
| 40 | + * .catch(err => console.log('Error tracking view:', err)); |
| 41 | + * |
| 42 | + * |
| 43 | + * // Set user id |
| 44 | + * this.analyticsFirebase.setUserId('USER-ID') |
| 45 | + * .then(() => console.log('User id successfully set')) |
| 46 | + * .catch(err => console.log('Error setting user id:', err)); |
| 47 | + * |
| 48 | + * |
| 49 | + * // Set user property from default properties |
| 50 | + * this.analyticsFirebase.setUserProperty('KEY', 'VALUE') |
| 51 | + * .then(() => console.log('User property successfully set')) |
| 52 | + * .catch(err => console.log('Error setting user property:', err)); |
| 53 | + * |
| 54 | + * ``` |
| 55 | + */ |
| 56 | +@Plugin({ |
| 57 | + pluginName: 'AnalyticsFirebase', |
| 58 | + plugin: 'cordova-plugin-analytics', |
| 59 | + pluginRef: 'analytics', |
| 60 | + repo: 'https://github.com/appfeel/analytics-google', |
| 61 | + platforms: ['Android', 'iOS'] |
| 62 | +}) |
| 63 | +@Injectable() |
| 64 | +export class AnalyticsFirebase extends IonicNativePlugin { |
| 65 | + /** |
| 66 | + * This enum represents AnalyticsFirebase default events. |
| 67 | + * Use one of these default events or a custom event |
| 68 | + * @readonly |
| 69 | + */ |
| 70 | + @CordovaProperty |
| 71 | + readonly DEFAULT_EVENTS: { |
| 72 | + ADD_PAYMENT_INFO: string; |
| 73 | + ADD_TO_CART: string; |
| 74 | + ADD_TO_WISHLIST: string; |
| 75 | + APP_OPEN: string; |
| 76 | + BEGIN_CHECKOUT: string; |
| 77 | + CAMPAIGN_DETAILS: string; |
| 78 | + CHECKOUT_PROGRESS: string; |
| 79 | + EARN_VIRTUAL_CURRENCY: string; |
| 80 | + ECOMMERCE_PURCHASE: string; |
| 81 | + GENERATE_LEAD: string; |
| 82 | + JOIN_GROUP: string; |
| 83 | + LEVEL_END: string; |
| 84 | + LEVEL_START: string; |
| 85 | + LEVEL_UP: string; |
| 86 | + LOGIN: string; |
| 87 | + POST_SCORE: string; |
| 88 | + PRESENT_OFFER: string; |
| 89 | + PURCHASE_REFUND: string; |
| 90 | + REMOVE_FROM_CART: string; |
| 91 | + SEARCH: string; |
| 92 | + SELECT_CONTENT: string; |
| 93 | + SET_CHECKOUT_OPTION: string; |
| 94 | + SHARE: string; |
| 95 | + SIGN_UP: string; |
| 96 | + SPEND_VIRTUAL_CURRENCY: string; |
| 97 | + TUTORIAL_BEGIN: string; |
| 98 | + TUTORIAL_COMPLETE: string; |
| 99 | + UNLOCK_ACHIEVEMENT: string; |
| 100 | + VIEW_ITEM: string; |
| 101 | + VIEW_ITEM_LIST: string; |
| 102 | + VIEW_SEARCH_RESULTS: string; |
| 103 | + }; |
| 104 | + |
| 105 | + /** |
| 106 | + * This enum represents AnalyticsFirebase default params. |
| 107 | + * Use one of these default params or a custom param |
| 108 | + * @readonly |
| 109 | + */ |
| 110 | + @CordovaProperty |
| 111 | + readonly DEFAULT_PARAMS: { |
| 112 | + ACHIEVEMENT_ID: string; |
| 113 | + ACLID: string; |
| 114 | + AFFILIATION: string; |
| 115 | + CAMPAIGN: string; |
| 116 | + CHARACTER: string; |
| 117 | + CHECKOUT_OPTION: string; |
| 118 | + CHECKOUT_STEP: string; |
| 119 | + CONTENT: string; |
| 120 | + CONTENT_TYPE: string; |
| 121 | + COUPON: string; |
| 122 | + CP1: string; |
| 123 | + CREATIVE_NAME: string; |
| 124 | + CREATIVE_SLOT: string; |
| 125 | + CURRENCY: string; |
| 126 | + DESTINATION: string; |
| 127 | + END_DATE: string; |
| 128 | + FLIGHT_NUMBER: string; |
| 129 | + GROUP_ID: string; |
| 130 | + INDEX: string; |
| 131 | + ITEM_BRAND: string; |
| 132 | + ITEM_CATEGORY: string; |
| 133 | + ITEM_ID: string; |
| 134 | + ITEM_LIST: string; |
| 135 | + ITEM_LOCATION_ID: string; |
| 136 | + ITEM_NAME: string; |
| 137 | + ITEM_VARIANT: string; |
| 138 | + LEVEL: string; |
| 139 | + LEVEL_NAME: string; |
| 140 | + LOCATION: string; |
| 141 | + MEDIUM: string; |
| 142 | + METHOD: string; |
| 143 | + NUMBER_OF_NIGHTS: string; |
| 144 | + NUMBER_OF_PASSENGERS: string; |
| 145 | + NUMBER_OF_ROOMS: string; |
| 146 | + ORIGIN: string; |
| 147 | + PRICE: string; |
| 148 | + QUANTITY: string; |
| 149 | + SCORE: string; |
| 150 | + SEARCH_TERM: string; |
| 151 | + SHIPPING: string; |
| 152 | + SOURCE: string; |
| 153 | + START_DATE: string; |
| 154 | + SUCCESS: string; |
| 155 | + TAX: string; |
| 156 | + TERM: string; |
| 157 | + TRANSACTION_ID: string; |
| 158 | + TRAVEL_CLASS: string; |
| 159 | + VALUE: string; |
| 160 | + VIRTUAL_CURRENCY_NAME: string; |
| 161 | + }; |
| 162 | + |
| 163 | + /** |
| 164 | + * Logs an app event. The event can have up to 25 parameters. |
| 165 | + * Events with the same name must have the same parameters. |
| 166 | + * Up to 500 event names are supported. |
| 167 | + * Using predefined [FirebaseAnalytics.Event](https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event.html) and/or [FirebaseAnalytics.Param](https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Param.html) is recommended for optimal reporting. |
| 168 | + * |
| 169 | + * @param eventName {string} The event name |
| 170 | + * @param eventParams {object} (Optional) The event params |
| 171 | + * @return {Promise<any>} Returns a promise that resolves when the event is logged |
| 172 | + */ |
| 173 | + @Cordova() |
| 174 | + logEvent(eventName: string, eventParams?: object): Promise<any> { |
| 175 | + return; |
| 176 | + } |
| 177 | + |
| 178 | + /** |
| 179 | + * Clears all analytics data for this app from the device and resets the app instance id |
| 180 | + * @return {Promise<any>} Returns a promise that resolves when the analytics data is cleared |
| 181 | + */ |
| 182 | + @Cordova() |
| 183 | + resetAnalyticsData(): Promise<any> { |
| 184 | + return; |
| 185 | + } |
| 186 | + |
| 187 | + /** |
| 188 | + * Sets whether analytics collection is enabled for this app on this device. This setting is persisted across app sessions. By default it is enabled |
| 189 | + * @param screenName {boolean} The value of the collection |
| 190 | + * @return {Promise<any>} Returns a promise that resolves when the collection is enabled/disabled |
| 191 | + */ |
| 192 | + @Cordova() |
| 193 | + setAnalyticsCollectionEnabled(enabled: boolean): Promise<any> { |
| 194 | + return; |
| 195 | + } |
| 196 | + |
| 197 | + /** |
| 198 | + * Sets the current screen name, which specifies the current visual context in your app. |
| 199 | + * This helps identify the areas in your app where users spend their time and how they interact with your app |
| 200 | + * @param screenName {string} The screen name |
| 201 | + * @return {Promise<any>} Returns a promise that resolves when the current screen is setted |
| 202 | + */ |
| 203 | + @Cordova() |
| 204 | + setCurrentScreen(screenName: string): Promise<any> { |
| 205 | + return; |
| 206 | + } |
| 207 | + |
| 208 | + /** |
| 209 | + * Sets the minimum engagement time required before starting a session. The default value is 10000 (10 seconds) |
| 210 | + * @param screenName {number} The duration in milliseconds |
| 211 | + * @return {Promise<any>} Returns a promise that resolves when the minimum session duration is set |
| 212 | + */ |
| 213 | + @Cordova() |
| 214 | + setMinimumSessionDuration(milliseconds: number): Promise<any> { |
| 215 | + return; |
| 216 | + } |
| 217 | + |
| 218 | + /** |
| 219 | + * Sets the duration of inactivity that terminates the current session. The default value is 1800000 (30 minutes) |
| 220 | + * @param screenName {number} The duration in milliseconds |
| 221 | + * @return {Promise<any>} Returns a promise that resolves when the session timeout duration is set |
| 222 | + */ |
| 223 | + @Cordova() |
| 224 | + setSessionTimeoutDuration(milliseconds: number): Promise<any> { |
| 225 | + return; |
| 226 | + } |
| 227 | + |
| 228 | + /** |
| 229 | + * Sets the user ID property. This feature must be used in accordance with Google's Privacy Policy |
| 230 | + * @param userId {string} The user id |
| 231 | + * @return {Promise<any>} Returns a promise that resolves when the user id is setted |
| 232 | + */ |
| 233 | + @Cordova() |
| 234 | + setUserId(userId: string): Promise<any> { |
| 235 | + return; |
| 236 | + } |
| 237 | + |
| 238 | + /** |
| 239 | + * Sets a user property to a given value. Up to 25 user property names are supported. Once set, user property values persist throughout the app lifecycle and across sessions |
| 240 | + * @param userPropertyName {string} The user property name |
| 241 | + * @param userPropertyValue {string} The user property value |
| 242 | + * @return {Promise<any>} Returns a promise that resolves when the user property setted |
| 243 | + */ |
| 244 | + @Cordova() |
| 245 | + setUserProperty(userPropertyName: string, userPropertyValue: string): Promise<any> { |
| 246 | + return; |
| 247 | + } |
| 248 | +} |
0 commit comments