BranchMetrics / unity-branch-deep-linking-attribution

The Branch Unity SDK for deep linking and attribution. Branch helps mobile apps grow with deep links / deeplinks that power paid acquisition and re-engagement campaigns, referral programs, content sharing, deep linked emails, smart banners, custom user onboarding, and more.
https://docs.branch.io/apps/unity/
MIT License
118 stars 25 forks source link

Not receiving success or fail callback from Branch.initSession() #172

Closed Callum-Abele closed 4 years ago

Callum-Abele commented 4 years ago

I'm currently attempting to update our Branch SDK to the latest version available.

Functionality is now breaking in the app because I am no longer receiving a callback from Branch.initSession() call.

After extensive debugging I can see the Intent in logcat with the correct referral information that was embedded in the link from the referrer

I also log this in the activity that receives the intent, so I know the information is being received correctly at the Activity level.

Now the problem occurs when I call Branch.initSession(BranchInitCallBack) from a Unity script.

I have traced the logs all the way to the BranchAndroidWrapper.cs then at this point the code crosses the AndroidUnity bridge via the call to

_getBranchClass().CallStatic("initSession", callbackId);

At this point I receive nothing back, no error or success callback, I would assume if something was wrong with my setup I would be receiving the error callback?

Before I updated the SDK, the callback was pretty much instantaneous however now it seems to never call.

Any ideas / gotchas or suggestions in what I could be missing would be appreciated.

Thanks

Callum-Abele commented 4 years ago

Update on this issue. I am now successfully getting a callback returned from the Branch.initSession

my callback signature is the following

public static void BranchInitCallBack(Dictionary<string, object> parameters, string error)

When the callback is triggered the error is not nil but now after the SDK update I am receiving very few keys in the parameters argument via the callback.

I can generate the same Branch Link and open this on the old version of the app using the old sdk and the current dev version of the app using the upto date SDK, both versions successfully launch the app but I am not receiving the full parameter list I expect.

Pre SDK Update the parameters dictionary returns the following keys and values

{ $og_title=3D World $publicly_indexable=True ~creation_source=3 $og_description=Join! . $locally_indexable=True +click_timestamp=1579541223 $identity_id=723135505538000027 version=2 $og_image_url=http://cdn.ava.com/content/Branch/split.jpg ~feature=share +match_guaranteed=True $canonical_identifier=share/frontpage +clicked_branch_link=True $one_time_use=False ~id=74623450356135695432 souqaid=11231 friendcode=R45-CQV +is_first_session=False ~referring_link=https://get.ava.com/yyBlWgVXg3 ~channel=Pasteboard $exp_date=0 username=username123 }

However after integrating the new SDK the parameters dictionary is much smaller

{ +non_branch_link=ava://open +clicked_branch_link=False +is_first_session=False }

All the meta data is not present along with most of the properties I set when I generated the BranchUniversalObject, such as canonicalIdentifier

Is there something I'm missing here?

antonargunov commented 4 years ago

@Callum-Abele thank for the report, let me check please, I will answer asap.

Callum-Abele commented 4 years ago

@antonargunov Thanks for the quick response.

I've been playing around with the UnityTestBed that ships with the latest Unity SDK update.

After configuring the BranchPrefab with my keys and app URI's I installed the TestBed app onto 2 Android devices.

Using the app I created a Branch Link on the first device, then I opened that branch link on the second device expecting the logs to output all the BUO information embedded in the Branch Link from the first device,

What actually happens is there was no branch data, no meta data it had all been lost somehow.

This was all using the 4.2.1_core.jar file which is the same version I am trying to update to on my main project. As a test I replaced the core.jar file with my old 2.18.1_core.jar that I am trying to update from.

I then re-compiled the application and deployed on both devices again. After doing this I am now successfully receiving all data from the Branch links.

This shows that for some reason the 4.2.1_core.jar is not successfully retrieving Branch information.

I'll add more debug info when I can

antonargunov commented 4 years ago

@Callum-Abele thanks for report, I found the same yesterday and sent a request to android native team. I think on Friday/Monday we will have updated SDK

Callum-Abele commented 4 years ago

@antonargunov Thanks, will keep my eyes peeled for the update, do you have an estimate on when we can expect a fix?

Callum-Abele commented 4 years ago

Hi @antonargunov can you please confirm you are getting the same issues using the Unity plugin for iOS also?

I have just deployed the Testbed on an iOS device and I am getting no metadata from a link generated via the testbed.

UPDATE: I have now got iOS working correctly with the latest version of the Branch SDK, Android still does not work for me though

bklastaitis-branch commented 4 years ago

@Callum-Abele thanks for the report again. The issue should be resolved in the new release (0.6.0)

Callum-Abele commented 4 years ago

Hi @bklastaitis-branch thanks for the update, after importing the latest plugin I am now receiving an error object back from the callback

ReferralManager: Error = Warning. Session initialization already happened. To force a new session, set intent extra, "branch_force_new_session", to true.

This sounds like it needs to be set from the Android side of the plugin? is their a c# accessor function for this?

antonargunov commented 4 years ago

@Callum-Abele what is version of SDK?

Callum-Abele commented 4 years ago

@antonargunov 0.6.0

antonargunov commented 4 years ago

@Callum-Abele can you write steps to reproduce? what did you do? just open the app? open and then click the link? etc.

Callum-Abele commented 4 years ago

I'll check this in your sample app to make sure its not something on my setup will keep you informed

Callum-Abele commented 4 years ago

@antonargunov Hi Anton, I've been using the UnityTestbed from the latest sdk and it all seems to be working, so it seems to be a fault with our setup.

I have been looking into how the error is created on the Android plugin and as far as I can understand this should only trigger if the app is already in the foreground and a new intent is passed to the app?

I have been testing our app with the app closed so I am unsure why I am receiving this error.

Is their an API from the Unity app to set intent extra, "branch_force_new_session", to true?

Callum-Abele commented 4 years ago

@antonargunov @bklastaitis-branch

I have now managed to replicate my issue on the test bed Unity project.

The issue occurs if I implement my own subclass of Application and reference this in the AndroidManifest.xml

I call Branch.getAutoInstance(getApplicationContext()) on my Application's onCreate call.

However when I launch the test bed I see the same error I get on my app

see attached screenshot 672D5398-01B7-4320-B69B-2BD0B1F2730B

I was under the impression this was the only call I had to make for sub-classing Application. Is this not correct now for the latest version of the SDK?

Callum-Abele commented 4 years ago

@antonargunov @bklastaitis-branch

I have now tried subclassing BranchUnityApp and calling super.onCreate. This does not work.

I have tried called BranchUtil.setPluginType(BranchUtil.PluginType.Unity) before Branch.getAutoInstance(this.getApplicationContext());

After adding this call I no longer get the error returned from the callback,

'Error = Warning. Session initialization already happened. To force a new session, set intent extra, "branch_force_new_session", to true.'

Is this the correct call to make now for custom applications as I do not see any references to this in your documentation.

Unfortunately even though the error is no longer being returned I am still not receiving my referral data in the callback, all I get is an object with 2 keys

{ +clicked_branch_link=False +is_first_session=False }

Any help / confirmation of this issue your side would be greatly appreciated.

antonargunov commented 4 years ago

@Callum-Abele I understood, look please at this: https://github.com/BranchMetrics/unity-branch-deep-linking-attribution/blob/master/AndroidWrapperProject/app/src/main/java/io/branch/unity/BranchUnityApp.java

https://github.com/BranchMetrics/unity-branch-deep-linking-attribution/blob/master/AndroidWrapperProject/app/src/main/java/io/branch/unity/BranchUnityActivity.java

If you need to do the same rows to your app and activity classes.

Callum-Abele commented 4 years ago

@antonargunov Hi Anton

It seems adding theBranchUtil.setPluginType(BranchUtil.PluginType.Unity) seems to be working for me now.

I think I had some caching issue occurring yesterday, after running a clean build and calling that function in my Application subclass onCreate, it seems to be working correctly now

antonargunov commented 4 years ago

@Callum-Abele we have uploaded new version with support of Unity 2019. Add please in you application OnCreate method the next calls:

BranchUtil.setPluginType(BranchUtil.PluginType.Unity);
Branch.getAutoInstance(this.getApplicationContext());
Branch.disableInstantDeepLinking(true);

If you will have any trouble - create please new ticket.

eb0KrY4k commented 2 years ago

At the moment I have the same error, the callback is not called

dustinkerstein commented 2 years ago

Any updates on this? I'm having the same issue with Unity 2020.3.29f1 + Android Pixel XL + Branch Unity SDK v0.6.7

dustinkerstein commented 2 years ago

Quick update - I was able to get it working in a vanilla Unity 2020.3.29f1 project. I will try to figure out why it's behaving differently on my project.

MorganMoon commented 2 years ago

I am also experiencing this issue, unity 2020.3.28f1 and Branch Unity SDK v0.6.7