Skip to content

Commit

Permalink
rework android ad revenue analytics
Browse files Browse the repository at this point in the history
fix android AppMetrica
improve android google play billing supported checks
  • Loading branch information
irov committed Sep 13, 2023
1 parent 14a9b28 commit c364ae0
Show file tree
Hide file tree
Showing 19 changed files with 355 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ public class MengineAnalytics {
public final static int EAET_TUTORIAL_COMPLETE = 9;
public final static int EAET_SCREEN_VIEW = 10;

public final static String EA_ADMEDIATION_APPLOVINMAX = "AppLovinMax";

public final static int EA_ADTYPE_BANNER = 0;
public final static int EA_ADTYPE_MREC = 1;
public final static int EA_ADTYPE_LEADER = 2;
public final static int EA_ADTYPE_INTERSTITIAL = 3;
public final static int EA_ADTYPE_APP_OPEN = 4;
public final static int EA_ADTYPE_REWARDED = 5;
public final static int EA_ADTYPE_REWARDED_INTERSTITIAL = 6;
public final static int EA_ADTYPE_NATIVE = 7;
public final static int EA_ADTYPE_CROSS_PROMO = 8;
public final static int EA_ADTYPE_UNKNOWN = 8;

public final static String EA_ADREVENUE_SOURCE = "SOURCE";
public final static String EA_ADREVENUE_TYPE = "TYPE";
public final static String EA_ADREVENUE_ADUNITID = "ADUNITID";
public final static String EA_ADREVENUE_PLACEMENT = "PLACEMENT";
public final static String EA_ADREVENUE_NETWORK = "NETWORK";
public final static String EA_ADREVENUE_REVENUE_PRECISION = "REVENUE_PRECISION";
public final static String EA_ADREVENUE_REVENUE_VALUE = "REVENUE_VALUE";
public final static String EA_ADREVENUE_REVENUE_CURRENCY = "REVENUE_CURRENCY";

private static MengineApplication m_application;
private static Map<String, Object> m_context = new HashMap<>();
private static Map<String, Object> m_getter = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,14 @@ public void onMengineAnalyticsFlush() {
}
}

public void onMengineAnalyticsRevenuePaid(Map<String, Object> paid) {
ArrayList<MenginePluginAnalyticsListener> listeners = this.getAnalyticsListeners();

for (MenginePluginAnalyticsListener l : listeners) {
l.onMengineAnalyticsRevenuePaid(this, paid);
}
}

private void invalidInitialize(String format, Object ... args) {
String msg = MengineLog.logError(TAG, format, args);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ protected void invalidInitialize(String format, Object ... args) throws MengineP
throw new MenginePluginInvalidInitializeException(message);
}

public void makeToastLong(String text, long delayed) {
if (m_activity == null) {
return;
}

MengineUtils.makeToastLong(m_activity, text, delayed);
}

public void sendEvent(MengineEvent event, Object ... args) {
MengineApplication application = this.getMengineApplication();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,30 @@ public interface MenginePluginAnalyticsListener extends MenginePluginInterface {
int EAET_TUTORIAL_COMPLETE = MengineAnalytics.EAET_TUTORIAL_COMPLETE;
int EAET_SCREEN_VIEW = MengineAnalytics.EAET_SCREEN_VIEW;

String EA_ADMEDIATION_APPLOVINMAX = MengineAnalytics.EA_ADMEDIATION_APPLOVINMAX;

int EA_ADTYPE_BANNER = MengineAnalytics.EA_ADTYPE_BANNER;
int EA_ADTYPE_MREC = MengineAnalytics.EA_ADTYPE_MREC;
int EA_ADTYPE_LEADER = MengineAnalytics.EA_ADTYPE_LEADER;
int EA_ADTYPE_INTERSTITIAL = MengineAnalytics.EA_ADTYPE_INTERSTITIAL;
int EA_ADTYPE_APP_OPEN = MengineAnalytics.EA_ADTYPE_APP_OPEN;
int EA_ADTYPE_REWARDED = MengineAnalytics.EA_ADTYPE_REWARDED;
int EA_ADTYPE_REWARDED_INTERSTITIAL = MengineAnalytics.EA_ADTYPE_REWARDED_INTERSTITIAL;
int EA_ADTYPE_NATIVE = MengineAnalytics.EA_ADTYPE_NATIVE;
int EA_ADTYPE_CROSS_PROMO = MengineAnalytics.EA_ADTYPE_CROSS_PROMO;

String EA_ADREVENUE_SOURCE = MengineAnalytics.EA_ADREVENUE_SOURCE;
String EA_ADREVENUE_TYPE = MengineAnalytics.EA_ADREVENUE_TYPE;
String EA_ADREVENUE_ADUNITID = MengineAnalytics.EA_ADREVENUE_ADUNITID;
String EA_ADREVENUE_PLACEMENT = MengineAnalytics.EA_ADREVENUE_PLACEMENT;
String EA_ADREVENUE_NETWORK = MengineAnalytics.EA_ADREVENUE_NETWORK;
String EA_ADREVENUE_REVENUE_PRECISION = MengineAnalytics.EA_ADREVENUE_REVENUE_PRECISION;
String EA_ADREVENUE_REVENUE_VALUE = MengineAnalytics.EA_ADREVENUE_REVENUE_VALUE;
String EA_ADREVENUE_REVENUE_CURRENCY = MengineAnalytics.EA_ADREVENUE_REVENUE_CURRENCY;

void onMengineAnalyticsEvent(MengineApplication application, int eventType, String eventName, long timestamp, Map<String, Object> bases, Map<String, Object> parameters);

void onMengineAnalyticsFlush(MengineApplication application);

void onMengineAnalyticsRevenuePaid(MengineApplication application, Map<String, Object> paid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public static Handler performOnMainThreadDelayed(Runnable runnable, long delayMi
}

public static void makeToastLong(Context context, String text, long delayed) {
MengineLog.logMessage(TAG, "Toast show after %d milliseconds text: %s"
, delayed
, text
);

MengineUtils.performOnMainThreadDelayed(() -> {
Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
toast.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Bundle;

import com.adjust.sdk.Adjust;
import com.adjust.sdk.AdjustAdRevenue;
import com.adjust.sdk.AdjustConfig;
import com.adjust.sdk.AdjustEvent;
import com.adjust.sdk.BuildConfig;
Expand All @@ -14,10 +15,13 @@
import org.Mengine.Base.MengineEvent;
import org.Mengine.Base.MenginePlugin;
import org.Mengine.Base.MenginePluginActivityListener;
import org.Mengine.Base.MenginePluginAnalyticsListener;
import org.Mengine.Base.MenginePluginApplicationListener;
import org.Mengine.Base.MenginePluginInvalidInitializeException;

public class MengineAdjustPlugin extends MenginePlugin implements MenginePluginApplicationListener, MenginePluginActivityListener {
import java.util.Map;

public class MengineAdjustPlugin extends MenginePlugin implements MenginePluginApplicationListener, MenginePluginActivityListener, MenginePluginAnalyticsListener {
public static final String PLUGIN_NAME = "Adjust";
public static final boolean PLUGIN_EMBEDDING = true;

Expand Down Expand Up @@ -91,6 +95,45 @@ public void onPause(MengineActivity activity) {
Adjust.onPause();
}

@Override
public void onMengineAnalyticsEvent(MengineApplication application, int eventType, String eventName, long timestamp, Map<String, Object> bases, Map<String, Object> parameters) {
//ToDo
}

@Override
public void onMengineAnalyticsFlush(MengineApplication application) {
//ToDo
}

private static String getAdjustMediationNetwork(String source) {
if (source.equalsIgnoreCase(EA_ADMEDIATION_APPLOVINMAX) == true) {
return AdjustConfig.AD_REVENUE_APPLOVIN_MAX;
}

return AdjustConfig.AD_REVENUE_SOURCE_PUBLISHER;
}

@Override
public void onMengineAnalyticsRevenuePaid(MengineApplication application, Map<String, Object> paid) {
String source = (String)paid.get(EA_ADREVENUE_SOURCE);
String AdjustSource = MengineAdjustPlugin.getAdjustMediationNetwork(source);
String network = (String)paid.get(EA_ADREVENUE_NETWORK);
int adType = (int)paid.get(EA_ADREVENUE_TYPE);
String adUnitId = (String)paid.get(EA_ADREVENUE_ADUNITID);
String placement = (String)paid.get(EA_ADREVENUE_PLACEMENT);
double revenue = (double)paid.get(EA_ADREVENUE_REVENUE_VALUE);
String revenuePrecision = (String)paid.get(EA_ADREVENUE_REVENUE_PRECISION);
String revenueСurrency = (String)paid.get(EA_ADREVENUE_REVENUE_CURRENCY);

AdjustAdRevenue adjustAdRevenue = new AdjustAdRevenue(AdjustSource);
adjustAdRevenue.setRevenue(revenue, revenueСurrency);
adjustAdRevenue.setAdRevenueNetwork(network);
adjustAdRevenue.setAdRevenueUnit(adUnitId);
adjustAdRevenue.setAdRevenuePlacement(placement);

Adjust.trackAdRevenue(adjustAdRevenue);
}

public void eventTraking(String token) {
this.logMessage("eventTraking token: %s"
, token
Expand Down

This file was deleted.

42 changes: 0 additions & 42 deletions gradle/plugins/AppLovin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ Utils.logAvailable("MENGINE_APP_PLUGIN_APPLOVIN_MEDIATION_VERVE", MENGINE_APP_PL
Utils.logAvailable("MENGINE_APP_PLUGIN_APPLOVIN_MEDIATION_YANDEX", MENGINE_APP_PLUGIN_APPLOVIN_MEDIATION_YANDEX)

def MENGINE_APP_PLUGIN_AMAZON = Utils.existAppPlugin(project, "MENGINE_APP_PLUGIN_AMAZON")
def MENGINE_APP_PLUGIN_FIREBASE_ANALYTICS = Utils.existAppPlugin(project, "MENGINE_APP_PLUGIN_FIREBASE_ANALYTICS")
def MENGINE_APP_PLUGIN_APPMETRICA = Utils.existAppPlugin(project, "MENGINE_APP_PLUGIN_APPMETRICA")

if (MENGINE_APP_PLUGIN_APPLOVIN_MEDIATION_AMAZON == true) {
if (MENGINE_APP_PLUGIN_AMAZON == false) {
Expand All @@ -77,46 +75,6 @@ android {
namespace "org.Mengine.Plugin.AppLovin"
}

Utils.logAvailable("AppLovin add Firebase Analytics extension", MENGINE_APP_PLUGIN_FIREBASE_ANALYTICS)

if (MENGINE_APP_PLUGIN_FIREBASE_ANALYTICS == true) {
android {
ext.extensions += 'org.Mengine.Plugin.AppLovin.MengineAppLovinExtensionFirebaseAnalytics'

sourceSets {
main {
java.srcDirs += ['FirebaseAnalytics']
}
}
}

dependencies {
implementation project(path: ':plugins:FirebaseAnalytics')

implementation 'com.google.firebase:firebase-analytics:21.3.0'
}
}

Utils.logAvailable("AppLovin add AppMetrica extension", MENGINE_APP_PLUGIN_APPMETRICA)

if (MENGINE_APP_PLUGIN_APPMETRICA == true) {
android {
ext.extensions += 'org.Mengine.Plugin.AppLovin.MengineAppLovinExtensionAppMetrica'

sourceSets {
main {
java.srcDirs += ['AppMetrica']
}
}
}

dependencies {
implementation project(path: ':plugins:AppMetrica')

implementation 'com.yandex.android:mobmetricalib:5.3.0'
}
}

Utils.logAvailable("AppLovin add Mediation Amazon extension", MENGINE_APP_PLUGIN_APPLOVIN_MEDIATION_AMAZON)

if (MENGINE_APP_PLUGIN_APPLOVIN_MEDIATION_AMAZON == true) {
Expand Down

This file was deleted.

Loading

0 comments on commit c364ae0

Please sign in to comment.