segmentio / analytics_flutter

The hassle-free way to add Segment analytics to your Flutter app.
MIT License
26 stars 33 forks source link

Ip address in events #43

Closed urvashi-k-7span closed 3 months ago

urvashi-k-7span commented 7 months ago

Hi there,

I am using this package. Called identify events as below

 Analytics? analytics;

  analytics = createClient(
      Configuration(
        AppConfig.of(context)?.segmentWriteKey ?? '',
        debug: false,
        collectDeviceId: true,
        trackApplicationLifecycleEvents: true,
      ),
    );

analytics?.identify(
      userId: session?.id.toString(),
      userTraits: UserTraits(
        custom: traits,
      ),
    );

But there is no IP address value in my segment data, From the IP address mix panel gets the region and country of the user and in my case that shows default region of mixpanel server. because an IP address is not being passed to the segment.

edsonjab commented 6 months ago

Hi @urvashik-7span thank you for your report, we start looking into this.

urvashi-k-7span commented 6 months ago

Hi any update? I am waiting for this and we had live app.

Hi @urvashik-7span thank you for your report, we start looking into this.

kupresk14 commented 6 months ago

We are seeing this as well, comparing tables to our old implementation

QoLTech commented 6 months ago

Yep, same here.

QoLTech commented 6 months ago

I've been doing some investigating and if the field used to be the public IP, I think Segment may be filling this data themselves after receiving the event server-side. I haven't found an Android or iOS API that exposes public API.

For some reason that field may not be filled if received from this library? Who can look into that for us?

QoLTech commented 6 months ago

Ahah!

https://segment.com/docs/connections/spec/common/#context:~:text=IP%20Address%20isn%E2%80%99t%20collected%20by%20Segment%E2%80%99s%20libraries%2C%20but%20is%20instead%20filled%20in%20by%20Segment%E2%80%99s%20servers%20when%20it%20receives%20a%20message%20for%20client%20side%20events%20only.

QoLTech commented 6 months ago

Yeah, exactly what I thought. I changed the context.library field to be ContextLibrary("analytics-android", "4.10.4"); in packages/core/lib/plugins/inject_context.dart and my events on the server now have a context.ip in the events.

Seems like the Segment server needs to be updated to recognize analytics-flutter as a library that needs context.ip added after an event is received.

@edsonjab @oscb Can either of your escalate this for us?

oscb commented 5 months ago

@QoLTech hey, sorry for the wait. I was out of office, but I'm raising this to the backend team.

QoLTech commented 5 months ago

@oscb I assumed - I hope it was refreshing! Thanks for looking into this. We've got a fork of this library where we're setting the context.library field, so it'd be nice to have this properly supported.

Heedster commented 5 months ago

@oscb any updates on this?

We just changed from the 3rd party flutter_segment lib to this, and released a version, and our mixpanel analytics dashboards are going crazy because of the lack of countryCode data. Is there anything that can be done for this?

Heedster commented 5 months ago

Fixed it temporarily by adding a custom plugin. This was suggested by Segment support.

import 'dart:async';

import 'package:analytics/event.dart';
import 'package:analytics/plugin.dart';
import 'package:flutter/foundation.dart' show kIsWeb;

// This plugin is a hack to ask segment servers to add the IP in the request.
// This solution was suggested by the segment team as they fix the actual issue.
class IPInAnalyticsPlugin extends Plugin {
  IPInAnalyticsPlugin() : super(PluginType.after);

  @override
  Future<RawEvent?> execute(RawEvent event) async {
    final addIp = <String, dynamic>{"direct": true};

    final context = event.context;

    if (context == null || kIsWeb) {
      return event;
    }

    context.custom.addAll(addIp);

    return event;
  }
}

Ideally should have been an enrichment plugin that sets context, however mergeContext method ignores merging custom

oscb commented 3 months ago

Sorry for the lack of updates, This was enabled in the backend at the start of this month. IP Addresses are stamped now at the server properly

milansurelia commented 3 months ago

Thank you @oscb 🙌🏻, This was a much needed fix.

urvashi-k-7span commented 3 months ago

Thank you 👍 @oscb

maxlapides commented 1 month ago

Hi @oscb, unfortunately we're still having this issue with our Flutter app on the latest version of this package. Do you have any other suggestions, is there a setting that we need to configure to get the IP addresses to be stamped on our events?