Skip to content

Commit

Permalink
final touch up fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fuziontech committed Jun 26, 2020
1 parent 2b1d716 commit 470d2ea
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.posthog.posthog_flutter;

import androidx.annotation.NonNull;

import android.app.Activity;
import android.content.Context;
import android.content.pm.ApplicationInfo;
Expand Down Expand Up @@ -43,13 +45,13 @@ public static void registerWith(PluginRegistry.Registrar registrar) {
}

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
setupChannels(binding.getApplicationContext(), binding.getBinaryMessenger());
}

private void setupChannels(Context applicationContext, BinaryMessenger messenger) {
try {
methodChannel = new MethodChannel(messenger, "posthog_flutter");
methodChannel = new MethodChannel(messenger, "posthogflutter");
this.applicationContext = applicationContext;

ApplicationInfo ai = applicationContext.getPackageManager()
Expand All @@ -62,19 +64,19 @@ private void setupChannels(Context applicationContext, BinaryMessenger messenger
Boolean captureApplicationLifecycleEvents = bundle.getBoolean("com.posthog.posthog.TRACK_APPLICATION_LIFECYCLE_EVENTS");
Boolean debug = bundle.getBoolean("com.posthog.posthog.DEBUG", false);

PostHog.Builder analyticsBuilder = new PostHog.Builder(applicationContext, writeKey, posthogHost);
PostHog.Builder posthogBuilder = new PostHog.Builder(applicationContext, writeKey, posthogHost);
if (captureApplicationLifecycleEvents) {
// Enable this to record certain application events automatically
analyticsBuilder.captureApplicationLifecycleEvents();
posthogBuilder.captureApplicationLifecycleEvents();
}

if (debug) {
analyticsBuilder.logLevel(LogLevel.DEBUG);
posthogBuilder.logLevel(LogLevel.DEBUG);
}

// Here we build a middleware that just appends data to the current context
// using the [deepMerge] strategy.
analyticsBuilder.middleware(
posthogBuilder.middleware(
new Middleware() {
@Override
public void intercept(Chain chain) {
Expand Down Expand Up @@ -103,7 +105,7 @@ public void intercept(Chain chain) {
// This state may happen after the app is popped (back button until the app closes)
// and opened again from the TaskManager.
try {
PostHog.setSingletonInstance(analyticsBuilder.build());
PostHog.setSingletonInstance(posthogBuilder.build());
} catch (IllegalStateException e) {
Log.w("PosthogFlutter", e.getMessage());
}
Expand Down Expand Up @@ -294,7 +296,7 @@ private void disable(MethodCall call, Result result) {
* Enables / disables / sets custom integration properties so Posthog can properly
* interact with 3rd parties, such as Amplitude.
* @see https://posthog.com/docs/connections/sources/catalog/libraries/mobile/android/#selecting-destinations
* @see https://github.com/posthogio/analytics-android/blob/master/analytics/src/main/java/com/posthog.android/Options.java
* @see https://github.com/posthogio/posthog-android/blob/master/posthog/src/main/java/com/posthog.android/Options.java
*/
@SuppressWarnings("unchecked")
private Options buildOptions(HashMap<String, Object> optionsData) {
Expand Down
1 change: 1 addition & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
Remember that the application lifecycle events won't have any
special context set for you by the time it is initialized. -->
<meta-data android:name="com.posthog.posthog.API_KEY" android:value="<YOUR_API_KEY_GOES_HERE>" />
<meta-data android:name="com.posthog.posthog.POSTHOG_HOST" android:value="https://app.posthog.com" />
<meta-data android:name="com.posthog.posthog.TRACK_APPLICATION_LIFECYCLE_EVENTS" android:value="false" />
<!--
If you want to debug the plugin events. Default is false.
Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/PosthogFlutterPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {

[PHGPostHog setupWithConfiguration:configuration];
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"posthog_flutter"
methodChannelWithName:@"posthogflutter"
binaryMessenger:[registrar messenger]];
PosthogFlutterPlugin* instance = [[PosthogFlutterPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];
Expand Down
6 changes: 3 additions & 3 deletions lib/src/posthog_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import 'package:flutter/services.dart';
import 'package:posthog_flutter/src/posthog_default_options.dart';
import 'package:posthog_flutter/src/posthog_platform_interface.dart';

const MethodChannel _channel = MethodChannel('posthog_flutter');
const MethodChannel _channel = MethodChannel('posthogflutter');

class PosthogMethodChannel extends PosthogPlatform {
Future<void> identify({
@required userId,
@required distinctId,
Map<String, dynamic> properties,
Map<String, dynamic> options,
}) async {
try {
await _channel.invokeMethod('identify', {
'userId': userId,
'distinctId': distinctId,
'properties': properties ?? {},
'options': options ?? PosthogDefaultOptions.instance.options ?? {},
});
Expand Down

0 comments on commit 470d2ea

Please sign in to comment.