recordEvent method

Future<void> recordEvent(
  1. Offset position,
  2. BuildContext context,
  3. bool debugMode,
  4. double scrooll,
  5. String path,
  6. Map<String, String>? properties,
  7. String? session,
)

Implementation

Future<void> recordEvent(
  Offset position,
  BuildContext context,
  bool debugMode,
  double scrooll,
  String path,
  Map<String, String>? properties,
  String? session,
) async {
  if (isInvalidToken(token)) return;

  try {
    final sizes = getUtilScreenSize(context);
    final double screenWidth = sizes[0];
    final double screenHeight = sizes[1];
    final List<double> pos = positionFromEvent(position, context);
    final Map<String, dynamic> eventBody = {
      "x": pos[0],
      "y": pos[1],
      "scroll": scrooll,
      "path": path,
      "screenWidth": screenWidth,
      "screenHeight": screenHeight,
      "os": getOS(),
      if (properties != null) 'props': properties,
    };

    final instance = HeatlensInstance();
    final String userSession = session ?? await instance.session();

    if (debugMode) debugPrint(jsonEncode(eventBody));
    await _post(body: {...eventBody, 'session': userSession});
  } catch (_) {
    return;
  }
}