Megacool SDK推荐系统问题:receivedShareOpened与sentShareOpened未触发
Hey there, let's break down why those critical referral events aren't triggering for you—especially since the console is picking up referral data, which means the core tracking is working under the hood. Here are targeted fixes and checks to try:
1. Verify Listener Registration Timing & Scope
- Make sure
Megacool.start()is called as early as possible in yourMainActivity'sonCreate()method—preferably beforesetContentView(). If you delay initialization (e.g., in an async task or after UI setup), the event might fire before your listener is registered. - Confirm your
MainActivityis the app's launcher activity. If users open the app via a referral link that routes to a different activity, your listener won't catch the event unless you register it there too (or initialize Megacool in a base activity that all entry points inherit from).
2. Validate isFirstSession() Logic
- Remember:
isFirstSession()only triggers if the receiver (device B) opens the app for the first time ever after installation. If you tested opening the app on device B before clicking the referral link, this check will fail. Try a clean test:- Uninstall the app from device B entirely.
- Install only via the referral link.
- Open the app immediately—this should trigger the event.
- Avoid calling
Megacool.getInstance().resetIdentity()repeatedly unless absolutely necessary, as it can disrupt session tracking.
3. Fix ProGuard/R8 Obfuscation Issues
If you're using code obfuscation, Megacool's event classes and listeners might be mangled, breaking callbacks. Add these rules to your proguard-rules.pro:
-keep class co.megacool.megacool.** { *; } -keep class co.megacool.** { *; } -keepattributes *Annotation*
Double-check that these rules apply to both debug and release builds—sometimes debug builds skip obfuscation, hiding the issue until you test a release variant.
4. Manually Refresh Pending Events
On device B, immediately after opening the app via the referral link, add this line to force Megacool to check for pending share events:
Megacool.getInstance().refresh();
This can trigger missed callbacks if the initial event check ran before your listener was ready.
5. Update to the Latest SDK Version
Older Megacool SDK versions have known bugs with event triggering. Update your Gradle dependency to the latest version (replace x.y.z with the current release number):
implementation 'co.megacool.megacool-android:megacool:x.y.z'
6. Double-Check API Key & Configuration
- Confirm the API key in
getString(R.string.megacool_api_key)matches exactly what's in your Megacool console—even a single typo or hidden whitespace can break event callbacks (while still allowing basic data to reach the console). - Scan your
MegacoolConfigsetup for accidental flags likedisableEventTracking()that might be blocking callback triggers.
If none of these work, add debug logs to check for pending shares:
Log.d(TAG, "Pending shares: " + Megacool.getInstance().getPendingShares()); Log.d(TAG, "Current user ID: " + Megacool.getInstance().getCurrentUser().getUserId());
This will help you confirm if Megacool detects the referral share at all, even if the callback isn't firing.
内容的提问来源于stack exchange,提问作者Adam Varhegyi

