GithubHelp home page GithubHelp logo

Comments (6)

fmmalta avatar fmmalta commented on June 14, 2024 1

I've figure it out

from amplitude-flutter.

haoliu-amp avatar haoliu-amp commented on June 14, 2024

Would you like to try our SDK without having your own wrapper/inheritance?
To do it, please follow the example. https://github.com/amplitude/Amplitude-Flutter

instance name is:
Name of the SDK instance (e.g. no name for the default instance or a custom name for a named instance).

from amplitude-flutter.

fmmalta avatar fmmalta commented on June 14, 2024

How can I retrieve the instance? Inherited? Instantiating a new one? It only has a function on README.md's example

Should I follow from example folder? Which means that I have to instantiate Amplitude right inside main.dart?

What's the difference between my code and the example? I know, perhaps the InheritedWidget AppState, that's why I'm asking.

from amplitude-flutter.

haoliu-amp avatar haoliu-amp commented on June 14, 2024

To retrieve the instance, do

    final Amplitude analytics = Amplitude.getInstance(instanceName: "project");

To initialize, do.

    // Initialize SDK
    analytics.init(widget.apiKey);

You don't need to call the constructor explicitly.

from amplitude-flutter.

fmmalta avatar fmmalta commented on June 14, 2024

So this analytics variable should be a global instance?

from amplitude-flutter.

fmmalta avatar fmmalta commented on June 14, 2024
class AppAnalytics {
  static Amplitude _analytics = Amplitude.getInstance();

  static Future<void> start() async {
    await _analytics.init(AppConfig.instance.analyticsKey);
  }

  static void initTrackWithUserId(String userId, {String screenName}) {
    _analytics
      ..setUserId(userId)
      ..trackingSessionEvents(true)
      ..logEvent('acessed_$screenName');
  }

  static void sendEvent(String event, {Map<String, dynamic> props}) {
    _analytics.logEvent(event, eventProperties: props);
  }
}

This is the new code, no more singletons, still not working, what I'm missing?

Does static functions is a problem? I've added some break points to check if the functions were being called correctly and they were, the key was being passed, the instance is not null... I don't know what else can be done.

from amplitude-flutter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.