How to implement TapJoy in Flutter

So i was working on a project earlier, of which whole business model depended on TapJoy SDK, as i kept searching for a flutter plugin for TapJoy, i didn’t find anything. So i decided to create a plugin for it.

Here i will explain how to build a full working example for the plugin with flutter.

First we need to add some modifications for both Android and iOS Files.

Let’s start with iOS.

As TapJoy is enrolled as a network partner in Apple’s SKAdNetwork. Add TapJoy’s network ID to your app’s info.plist file along with the IDs of the DSP partners listed below:

iOS 14.0 or higher requires App Tracking Authorisation from the user, so we need to add the following lines in info.plist if your app will user App Tracking Feature.

We also need to comment out the following line in our ios Podfile :

And for Android:

The following permissions are needed:

  • INTERNET
  • ACCESS_NETWORK_STATE
  • ACCESS_WIFI_STATE(optional)

Add the following lines to your flutterApp/android/app/src/main/AndroidManifest.

Add these activities to the AndroidManifest.xml file in the Application block:

As part of Google Play Services integration, we will have to add the following to the AndroidManifest.xml file:

To the fun part, let’s start building our example App.

add this line in you pubspec.yaml file under dependencies :

Next, run Flutter pub get in terminal:

Now let’s write some code

first we need to set connection handler so that we get notified when connection is established or failed.

let’s create handler first then set it.

now let’s set TapJoyConnectionResult handler:

Connect to TapJoy with Android & iOS TapJoy Api Keys & debug on true for development. (don’t forget to change the debug to false for production):

Then, set userID :

After successfully connecting to TapJoy, go to the TapJoy dashboard, developer console and set the device as test device:

TapJoy works with placements, so you will have to create a placement first in the TapJoy Dashboard and also create content for that placement.

Now we can create the placement in our flutter app, make sure to write the exact name of placement as in the dashboard as it’s case sensitive :

Now create a handler for the placement to notify us with changes such as request success, request fail, content ready, content shown or content disappeared.

UserClicked notification is supported for android devices ONLY

Now set the handler to the placement we just created:

We’re done ! now we can write functions to request and show content for our placement !

We might need to get user current Balance, award balance to user or deduct balance from user.

First Make sure you have a currency created and ready in TapJoy Dashboard for both iOS and Android.

Create Currency Handler :

Then set the currency handler:

You can set different currency handler for each function of those, but for simplicity i will set the same one for all of them:

Now you can get currency balance as follows, and u will receive the data in the handler that we’ve just set:

or deduct balance from user ( spend currency balance ):

or award the user some balance for being a loyal user:

In order to notify users that they’ve earned virtual currency since the last time the app queried the user’s currency balance, set earned currency alert handler:

That’s it ! we’ve covered everything we can do with the TapJoy Plugin for Flutter !

Plugin link on pub.dev website

you can check source code for the complete working example Here.

If you like the article, Don’t forget to throw some claps ;)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store