@@ -72,6 +72,20 @@ class Posthog {
7272 @internal
7373 String ? get currentScreen => _currentScreen;
7474
75+ /// Can associate events with specific users
76+ ///
77+ /// - [userId] A unique identifier for your user. Typically either their email or database ID.
78+ /// - [userProperties] the user properties, set as a "$set" property,
79+ /// - [userPropertiesSetOnce] the user properties to set only once, set as a "$set_once" property.
80+ ///
81+ /// **Example:**
82+ /// ```dart
83+ /// await Posthog().identify(
84+ /// userId: emailController.text,
85+ /// userProperties: {"name": "Peter Griffin", "email": "peter@familyguy.com"},
86+ /// userPropertiesSetOnce: {"date_of_first_log_in": "2024-03-01"}
87+ /// );
88+ /// ```
7589 Future <void > identify ({
7690 required String userId,
7791 Map <String , Object >? userProperties,
@@ -82,6 +96,29 @@ class Posthog {
8296 userProperties: userProperties,
8397 userPropertiesSetOnce: userPropertiesSetOnce);
8498
99+ /// Captures events.
100+ /// Docs https://posthog.com/docs/product-analytics/user-properties
101+ ///
102+ /// We recommend using a [object] [verb] format for your event names,
103+ /// where [object] is the entity that the behavior relates to,
104+ /// and [verb] is the behavior itself.
105+ /// For example, project created, user signed up, or invite sent.
106+ ///
107+ /// - [eventName] name of event
108+ /// - [properties] the custom properties
109+ /// - [userProperties] the user properties, set as a "$set" property,
110+ /// - [userPropertiesSetOnce] the user properties to set only once, set as a "$set_once" property.
111+ ///
112+ /// **Example**
113+ /// ```dart
114+ /// await Posthog().capture(
115+ /// eventName: 'user_signed_up',
116+ /// properties: {
117+ /// 'login_type': 'email',
118+ /// 'is_free_trial': true
119+ /// }
120+ /// );
121+ /// ```
85122 Future <void > capture ({
86123 required String eventName,
87124 Map <String , Object >? properties,
@@ -104,6 +141,10 @@ class Posthog {
104141 );
105142 }
106143
144+ /// Captures a screen view event
145+ ///
146+ /// - [screenName] the screen title
147+ /// - [properties] the custom properties
107148 Future <void > screen ({
108149 required String screenName,
109150 Map <String , Object >? properties,
@@ -115,39 +156,83 @@ class Posthog {
115156 );
116157 }
117158
159+ /// Creates an alias for the user.
160+ /// Docs https://posthog.com/docs/product-analytics/identify#alias-assigning-multiple-distinct-ids-to-the-same-user
161+ ///
162+ /// - [alias] the alias
118163 Future <void > alias ({
119164 required String alias,
120165 }) =>
121166 _posthog.alias (
122167 alias: alias,
123168 );
124169
170+ /// Returns the registered `distinctId` property
125171 Future <String > getDistinctId () => _posthog.getDistinctId ();
126172
173+ /// Resets all the cached properties including the `distinctId` .
174+ ///
175+ /// The SDK will behave as its been [setup] for the first time
127176 Future <void > reset () => _posthog.reset ();
128177
178+ /// Disable data collection for a user
129179 Future <void > disable () {
130180 // Uninstall Flutter-specific integrations when disabling
131181 _uninstallFlutterIntegrations ();
132182
133183 return _posthog.disable ();
134184 }
135185
186+ /// Enable data collection for a user
136187 Future <void > enable () => _posthog.enable ();
137188
189+ /// Check if the user has opted out of data collection
138190 Future <bool > isOptOut () => _posthog.isOptOut ();
139191
192+ /// Enable or disable verbose logs about the inner workings of the SDK.
193+ ///
194+ /// - [enabled] whether to enable or disable debug logs
140195 Future <void > debug (bool enabled) => _posthog.debug (enabled);
141196
197+ /// Register a property to always be sent with all the following events until you call
198+ /// [unregister] with the same key.
199+ ///
200+ /// - [key] the Key
201+ /// - [value] the Value
142202 Future <void > register (String key, Object value) =>
143203 _posthog.register (key, value);
144204
205+ /// Unregisters the previously set property to be sent with all the following events
206+ ///
207+ /// [key] the Key
145208 Future <void > unregister (String key) => _posthog.unregister (key);
146209
210+ /// Returns if a feature flag is enabled, the feature flag must be a Boolean
211+ ///
212+ /// Docs https://posthog.com/docs/feature-flags and https://posthog.com/docs/experiments
213+ ///
214+ /// - [key] the Key of the feature
147215 Future <bool > isFeatureEnabled (String key) => _posthog.isFeatureEnabled (key);
148216
217+ /// Reloads the feature flags
149218 Future <void > reloadFeatureFlags () => _posthog.reloadFeatureFlags ();
150219
220+ /// Creates a group.
221+ /// Docs https://posthog.com/docs/product-analytics/group-analytics
222+ ///
223+ /// - [groupType] the Group type
224+ /// - [groupKey] the Group key
225+ /// - [groupProperties] the Group properties, set as a "$group_set" property.
226+ ///
227+ /// **Example:**
228+ /// ```dart
229+ /// await Posthog().group(
230+ /// groupType: "company",
231+ /// groupKey: "company_id_in_your_db",
232+ /// groupProperties: {
233+ /// "name": "ACME Corp"
234+ /// });
235+ /// ```
151236 Future <void > group ({
152237 required String groupType,
153238 required String groupKey,
@@ -197,9 +282,9 @@ class Posthog {
197282
198283 /// Captures exceptions with optional custom properties
199284 ///
200- /// [error] - The error/exception to capture
201- /// [stackTrace] - Optional stack trace (if not provided, current stack trace will be used)
202- /// [properties] - Optional custom properties to attach to the exception event
285+ /// - [error] - The error/exception to capture
286+ /// - [stackTrace] - Optional stack trace (if not provided, current stack trace will be used)
287+ /// - [properties] - Optional custom properties to attach to the exception event
203288 Future <void > captureException (
204289 {required Object error,
205290 StackTrace ? stackTrace,
@@ -210,9 +295,9 @@ class Posthog {
210295 /// Captures runZonedGuarded exceptions with optional custom properties
211296 /// https://api.flutter.dev/flutter/dart-async/runZonedGuarded.html
212297 ///
213- /// [error] - The error/exception to capture
214- /// [stackTrace] - Optional stack trace (if not provided, current stack trace will be used)
215- /// [properties] - Optional custom properties to attach to the exception event
298+ /// - [error] - The error/exception to capture
299+ /// - [stackTrace] - Optional stack trace (if not provided, current stack trace will be used)
300+ /// - [properties] - Optional custom properties to attach to the exception event
216301 Future <void > captureRunZonedGuardedError (
217302 {required Object error,
218303 StackTrace ? stackTrace,
@@ -237,6 +322,7 @@ class Posthog {
237322 return _posthog.close ();
238323 }
239324
325+ /// Returns the session Id if a session is active
240326 Future <String ?> getSessionId () => _posthog.getSessionId ();
241327
242328 Posthog ._internal ();
0 commit comments