For some reason, I am unable to get the FB.LogAppEvent to work inside an android application built with Unity.
Based on the documentation I've read, the code below should work. But it's not producing results inside the analytics dashboard. You'll notice a method that produces an Android toast that confirms activation. This toast does appear on application start. I've tried multiple event types, including custom types from code generated by Facebook's event generator in the event documentation.
https://developers.facebook.com/docs/app-events/unity
https://developers.facebook.com/docs/unity/reference/current/FB.LogAppEvent/
private void Awake()
{
if (!FB.IsInitialized)
FB.Init( () => { OnInit(); } );
else
ActivateFacebook();
}
private void OnInit()
{
if (FB.IsInitialized)
ActivateFacebook();
else
ShowAndroidToastMessage("Failed To Initialize Facebook..");
}
private void ActivateFacebook()
{
FB.ActivateApp();
ShowAndroidToastMessage("Facebook Activated..");
FB.LogAppEvent(AppEventName.ActivatedApp);
}
I suppose the problem is in the way you send event
There are two methods for that:
LogAppEvent(string logEventName);
LogAppEvent(string logEventName, float valueToSum, Dictionary parameters = null);
You are using second method with "valueToSum" = 0, and that indicates there is nothing to sum, so your event probably gets skipped at some point.
You should use the first method
FB.LogAppEvent(AppEventName.ActivatedApp);
Also make sure your analytics is enabled in dashboard.
Do you see any built in analytic events? Feg. App Launches and other Standard events should be visible out of the box.
For me, LogAppEvent(...) successfully works with the Facebook Events Tracker and Analytics when you do a development build with Unity. When I switch to a release build, I then do not get any of the LogAppEvents other than the ActivateApp() notification.
Will update my answer when I get it working with a release build.
Related
I'm trying to add a BackdoorMethod to a Xamarin.Forms application to bypass the login (IDP - opened in chrome browser) step. I have the feeling that the method is not getting triggered, but not sure, and I don't know how could I make sure about it.
I've read the documentation here: https://learn.microsoft.com/en-us/appcenter/test-cloud/uitest/working-with-backdoors
Check this thread: https://forums.xamarin.com/discussion/85821/xamarin-uitest-backdoor-on-droid-with-splash-screen-how-do-i-access-my-mainactivity
Checked this example: https://github.com/brminnick/UITestSampleApp/tree/master/Src
In the MainActivity.cs file I've defined the BackdoorMethod:
[Preserve, Export(nameof(BypassLoginScreen))]
public string BypassLoginScreen()
{
// some additional code here. the code is working, when I called it
// directly from OnCreate it was executed without any error
return "called";
}
From the test case i'm trying to invoke it like:
public constructorMethod(Platform platform)
{
this.platform = platform;
app = AppInitializer.StartApp(platform);
var result = app.Invoke("BypassLoginScreen"); // result == "<VOID>"
}
I'm not getting any error message, the method simply not called, or not returns anything. (or i don't know what's happening there with it, because breakpoint also not working as the app started from the device)
This should be already working. I have similar code and it works for me.
you can add inside your function
Android.Util.Log.WriteLine(Android.Util.LogPriority.Info, "BypassLoginScreen", $"Some text as info");
And observe the result in Device Logs, Filter by BypassLoginScreen to see if there is any log created with the tag BypassLoginScreen
With Google sending out waves of warnings about the need to let users opt-in to crash reporting (source) I'm trying to build an opt-in dialog for Firebase Crashlytics.
To be able to do this I would need to know whether Crashlytics is currently enabled (to decide whether to show the dialog or not). It seems CrashlyticsCore.disabled is responsible for tracking this but I haven't found any way to access the value because it's package private and doesn't have an accessor. How can I know during runtime if Firebase Crashlytics is enabled?
The second thing I'd need to do is disable crash reporting by default and enable it when the user agrees to opt-in. How I suspected to be able to do this:
AndroidManifest:
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="false" />
Activity:
boolean userAgrees = true;
CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(!userAgrees).build();
Fabric.with(this, new Crashlytics.Builder().core(core).build());
throw new RuntimeException("why doesn't this show up in Firebase Crashlytics?");
Why isn't my RuntimeException showing up in Firebase Crashlytics?
P.S. Crashlytics is working fine when removing these attempts to create an opt-in dialog.
It seems toggling Crashlytics will only take effect after your app restarts. Fabric is a singleton and all calls to its Fabric.with method will simply be ignored after it's been initialized. Source code below.
public static Fabric with(Context context, Kit... kits) {
if (singleton == null) {
Class var2 = Fabric.class;
synchronized(Fabric.class) {
if (singleton == null) {
setFabric((new Fabric.Builder(context)).kits(kits).build());
}
}
}
return singleton;
}
One way around it is to keep track of the value yourself using SharedPreferences or other persistent storage methods and update your UI accordingly.
I was using an Android Native Plugin to connect to the leaderboard. At first, I made the application to connect to the google service using
GooglePlayConnection.instance.connect();
then when a button is clicked, the function below will be called.
public void ShowLeaderboard(string leaderboardName)
{
GooglePlayManager.instance.ShowLeaderBoard("leaderboard_score");
}
The application shows the connecting to box, but when i clicked on the button to show the leaderboard, nothing happens.
Then I tried to combine the two function into one like below, but the leaderboard is not showing either. The first click will show connecting to google play service box, but the second time did not show the leaderboard.
public void LeaderboardButton(){
if(GooglePlayConnection.state == GPConnectionState.STATE_CONNECTED) {
GooglePlayManager.instance.ShowLeaderBoard("leaderboard_score");
} else{
GooglePlayConnection.instance.connect ();
}
}
I would like to know is it because of the code or because of the settings in the android native window-> edit settings?
I'm assuming you have everything in your Google Play Developer Console setup right, with that being said after reading the documentation I believe line 3 should be GooglePlayManager.instance.ShowLeaderBoardsUI("leaderboard_score");
I want to check exceptions and errors in my game in built up, but there is no debug console in game so I want to make one. Is there any way to get those errors from original console and write it on screen?
You can add a callback function to Application.logMessageReceived to receive the Debug.* messages. For example:
void Awake(){
Application.logMessageReceived += HandleLog;
}
private void HandleLog(string logString, string stackTrace, LogType type) {
// add them to some UI component for visualizing
}
Lately, I have been trying to add static interstitial ads into my Unity game. For some reason, I could not get the system to show anything, or even react to me. After trying to work with the base Chartboost plugin, I tried to match a tutorial that I was following and purchased Prime31's Chartboost plugin and have been using that. However, neither the base plugin, nor Prime31's plugin, seem to be allowing me to show any ads. The code is pretty much done inside a single object, and it seems simple enough.
public class Advertisement : MonoBehaviour {
public string chartboostAppID = "5461129ec909a61e38b1505b";
public string chartboostAppSignature = "672b3b34e3e358e7a003789ddc36bd2bc49ea3b5";
// Use this for initialization
void Start () {
DontDestroyOnLoad(this.gameObject);
ChartboostAndroid.init (chartboostAppID, chartboostAppSignature, true);
ChartboostAndroid.cacheInterstitial(null);
}
void OnLevelWasLoaded(int level) {
ChartboostAndroid.cacheInterstitial(null);
if(Application.loadedLevelName == "Network Lobby") {
showAds();
}
}
public static void showAds() {
Debug.Log("Showing ad");
ChartboostAndroid.showInterstitial(null);
}
}
As you can see, it's pretty straightforward. This object is created at the game's splash screen, which appears only once, and it's never destroyed until the program ends. The goal is, whenever I enter the lobby scene, I want to see an ad before going to the lobby's menus. As it is, I do see the log printing "Showing ad", so I know the function is being called. However, nothing appears. Do I need to disable the GUI system first? Is there a step I'm missing?
I have already performed the following steps:
I have created and registered the app with chartboost, as well as double and triple checked the AppID and App Signature.
I have created a publishing campaign and registered it to the app.
I double-checked the orientation and confirmed that it's correct.
I registered this specific device as a test device.
The tutorial showed a call to ChartBoostAndroid.OnStart(), but there was no function like that for me to call. Perhaps that is from an older version?
I emailed Chartboost support and have not heard from them yet. I do not have that much time on this project, so if anyone can offer help, I'd appreciate it.