Flurry Analytics, Buildbox 2.3.8 And Android Export

Discussion in 'Technical Discussion' started by adrianjgomez, Sep 25, 2019.

  1. adrianjgomez

    adrianjgomez Boxer

    Joined:
    Apr 1, 2016
    Messages:
    68
    Likes Received:
    45
    Go to https://www.flurry.com/ create an account and an app.

    1. Drag URL Buttons over actions that you want to track.
    flurry1.png

    2. Make sure it isn't blocked so that your button also gets pressed. For the URL "#ana." is required. The format is as follows:
    #ana.<event>.<param>
    The event is required. The param is optional and it always it saves it with a key of "name".
    In the screenshot below, it would record event "scene" with a param of "option".
    Some examples of other possible events:
    #ana.rewardAd.show
    #ana.restartGame

    flurry2.png
    3. After export for Android in the build.gradle file under the dependencies add:
    Code:
    dependencies {
       // Pre filled lines up here. Don't remove.
        // More deps here //
        implementation 'com.flurry.android:analytics:11.4.0' //<---- Add this line.
    }
    
    4. In the src/main/java/com/secrethq/utils/PTServicesBridge.java add:
    Code:
    //Other imports above this line.
    import com.flurry.android.FlurryAgent; <- Add this import.
    
    5. In the same file in the openURL method add these lines:

    Code:
    public static void openUrl( String url ){
            Log.v(TAG, "PTServicesBridge  -- Open URL " + url);
    
    //Start of additional lines.
            if (url.startsWith("#ana")) {
    
                Log.v("Analytics", "Analytics  -- Record event.");
                String[] params = url.split("\\.");
    
                if (params[1] != null && params[1] != "") {
                    if (params.length == 3 && params[2] != "") {
                        HashMap<String, String> eventParam = new HashMap<>();
                        eventParam.put("name", params[2]);
                        FlurryAgent.logEvent(params[1], eventParam);
                    } else {
                        FlurryAgent.logEvent(params[1]);
                    }
                }
    
    
            } else {
    // End of additional lines.
                PTServicesBridge.urlString = url;
    
    
                PTServicesBridge.s_activity.get().runOnUiThread(new Runnable() {
                    public void run() {
                        try {
                            final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(PTServicesBridge.urlString));
                            PTServicesBridge.activity.startActivity(intent);
                        } catch (Exception e) {
                            //Print exception
                            Log.d(TAG, "OpenURL: Failed.");
                            e.printStackTrace();
                        }
                    }
                });
    
            }
        }
    
    6. In src/main/java/org/cocos2dx/lib/Cocos2dxActivity.java add the flurry import exactly like in step 4.
    7. In the same file as step 6, inside the create function and the flurry lines:

    Code:
    @Override
        protected void onCreate(final Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            sContext = this;
            this.mHandler = new Cocos2dxHandler(this);
    
            this.init();
    //Start of inserted code.
            new FlurryAgent.Builder()
                    .withLogEnabled(true) // <-- Set to false before releasing prod version.
                    .withCaptureUncaughtExceptions(true) // <-- Will record crashes if set to true.
                    .withContinueSessionMillis(10000)
                    .build(this, "youAppKey");  // <--- At the end of the flurry add app key.
    //End of inserted code.
            Cocos2dxHelper.init(this, this);
    
    
        }
    
    I am not in any way associated with Flurry. Please post here if you have any questions.
     

Share This Page