Skip to content

Commit c8a2315

Browse files
committed
- Refactor total request to use MixpanelSegmentationRequest model with nullable 'unit'
fix-(an Improvealytics code): consistency add and missing prepare ' forunit future' metric parameter work for Mixpanel
1 parent 8ea795c commit c8a2315

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/src/services/analytics/mixpanel_data_client.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class MixpanelDataClient implements AnalyticsReportingClient {
9393
event: metricName,
9494
fromDate: DateFormat('yyyy-MM-dd').format(startDate),
9595
toDate: DateFormat('yyyy-MM-dd').format(endDate),
96+
unit: MixpanelTimeUnit.day,
9697
);
9798

9899
final response = await _httpClient.get<Map<String, dynamic>>(
@@ -142,17 +143,19 @@ class MixpanelDataClient implements AnalyticsReportingClient {
142143

143144
_log.info('Fetching total for metric "$metricName" from Mixpanel.');
144145

145-
// To get a single total, we call the segmentation endpoint *without* the 'unit' parameter.
146-
final queryParameters = {
147-
'project_id': _projectId,
148-
'event': metricName,
149-
'from_date': DateFormat('yyyy-MM-dd').format(startDate),
150-
'to_date': DateFormat('yyyy-MM-dd').format(endDate),
151-
};
146+
// To get a single total, we call the segmentation endpoint without the 'unit'
147+
// parameter. The MixpanelSegmentationRequest model supports this by having
148+
// a nullable 'unit'.
149+
final request = MixpanelSegmentationRequest(
150+
projectId: _projectId,
151+
event: metricName,
152+
fromDate: DateFormat('yyyy-MM-dd').format(startDate),
153+
toDate: DateFormat('yyyy-MM-dd').format(endDate),
154+
);
152155

153156
final response = await _httpClient.get<Map<String, dynamic>>(
154157
'/segmentation',
155-
queryParameters: queryParameters,
158+
queryParameters: request.toJson(),
156159
);
157160

158161
final segmentationData =

0 commit comments

Comments
 (0)