Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setAttributionChangedDelegate and getAttribution doesn't work on iOS #306

Open
kekchpek opened this issue Aug 27, 2024 · 3 comments
Open

Comments

@kekchpek
Copy link

public void Init()
{
    AdjustConfig adjustConfig = new AdjustConfig(AppToken, Environment, false);
    adjustConfig.setLogLevel(AdjustLogLevel.Info);
    adjustConfig.setSendInBackground(false);
    adjustConfig.setEventBufferingEnabled(false);
    adjustConfig.setLaunchDeferredDeeplink(true);
    adjustConfig.setDefaultTracker(string.Empty);
    adjustConfig.setUrlStrategy(AdjustUrlStrategy.Default.ToString());
    adjustConfig.setAppSecret(0, 0, 0, 0, 0);
    adjustConfig.setDelayStart(0d);
    adjustConfig.setNeedsCost(false);
    adjustConfig.setPreinstallTrackingEnabled(false);
    adjustConfig.setPreinstallFilePath(string.Empty);
    adjustConfig.setAllowAdServicesInfoReading(true);
    adjustConfig.setAllowIdfaReading(true);
    adjustConfig.setCoppaCompliantEnabled(false);
    adjustConfig.setPlayStoreKidsAppEnabled(false);
    adjustConfig.setLinkMeEnabled(false);
    adjustConfig.setAttributionChangedDelegate(OnConversationReceived);
    Adjust.start(adjustConfig);

    OnConversationReceived(Adjust.getAttribution());
}

private void OnConversationReceived(AdjustAttribution attribution)
{
    // Handle attribution data
}

I use the code above to initialize adjust sdk and handle attribution data. It works well on Android devices. But I have problems on iOS. The callback I set with setAttributionChangedDelegate isn't called and Adjust.getAttribution() returns null. What can be a reason? Maybe I have to add something in plist or configure AdjustConfig in some other way?

@uerceg
Copy link
Contributor

uerceg commented Aug 27, 2024

Hi @kekchpek,

This should work fine in case you have added Adjust.prefab to your scene. However, if you are using some game object named differently (not Adjust) where you are loading Adjust.cs script, then you should pass that GO name as a 2nd (optional) parameter of the setAttributionChangedDelegate method. If that's the case, give this a shot:

adjustConfig.setAttributionChangedDelegate(OnConversationReceived, "MyGameObjectName");

Looking forward to hearing back from you if this helped.

@kekchpek
Copy link
Author

kekchpek commented Aug 27, 2024

Firstly, I don't use GameObject at all. This code is put in regular C# class. Your suggestion doesn't seem platform dependent. Why don't I have issues on Android in this case if problem connected with Unity-level GameObject?

Secondly this doesn't explain why Adjust.getAttribution() returns null. It doesn't connected with GameObjects at all.

Anyway I'll try to make a GameObject and follow your advice, thank you.

@uerceg
Copy link
Contributor

uerceg commented Aug 27, 2024

Issue in Android doesn't exist due to the nature of implementation of communication between C# and native Android (Java) layer. In iOS, it's working in a bit different way where when the message from native is supposed to be sent to Unity layer, it works practically via (for sake of easier explanation) some form of reflection. In particular, this line: https://github.com/adjust/unity_sdk/blob/v4.38.1/Assets/Adjust/iOS/AdjustUnityDelegate.mm#L113. This is where attribution obtained natively is attempted to be sent to C# layer. UnitySendMessage is trying to send message to game object (first parameter) which is having method with specified name (second parameter) implemented. This is implemented inside of the Adjust.cs script (https://github.com/adjust/unity_sdk/blob/v4.38.1/Assets/Adjust/Unity/Adjust.cs#L986) which normally gets loaded inside of the Adjust.prefab in which case default GO name being set to "Adjust" makes things work. However, if you decide to load Adjust script elsewhere, then you should state the other name.

When it comes to Adjust.getAttribution() returning null, you're right, this has nothing to do with the GO since it's a sync mechanism for which we don't need to use UnitySendMessage logic under the hood. Attribution information is something that is generated on the backend and SDK initially doesn't contain this information. For SDK to obtain attribution, upon first launch of the SDK ever, SDK needs to track install session first (initial request sent to backend), wait for a bit (around 2 seconds) and then ask for attribution information from the backend which, if the attribution is finalized, sends it back to SDK. In this moment, attribution callback should get triggered and from that moment on, Adjust.getAttribution() method should be returning actual attribution value and not null.

If the SDK has obtained attribution, attribution getter shouldn't be returning null even if attribution callback has not been triggered due to some potential integration issue we're discussing about. So that part is weird. In order to understand what's happening, it would be helpful to see what is SDK natively logging when you run the app from the Xcode. If you don't make it work and would like us to check what's up, it would be good to get logs after run like this:

  1. Uninstall app from your device.
  2. Set SDK to sandbox environment.
  3. Set log level to verbose.
  4. Run the app on your device and send over all the logs that SDK dumps (all of them are prefixed with [Adjust]).

Also, if you are up for, you can upgrade Adjust SDK to SDK v5.0.1 where we have replaced UnitySendMessage with MonoPInvokeCallback logic which should eliminate this GO SDK v4 concern from above. And also, getAttribution() is async getter in v5.0.1 so that you don't need to think about timing of this call, but invoke it and get it triggered as soon as SDK obtains the attribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants