Skip to main content

Pushwoosh and Adjust Integration


Push-notifications in all applications must be developed in accordance with the following instructions:
Notification Factory
Customize Android SDK


Steps:

  1. Include the following Maven repository URL in project's build.gradle:


allprojects {

    repositories {

        google ()

        mavenCentral()

    } 

}


  1. Add pushwoosh library dependencies into your application's build.gradle:


implementation 'com.pushwoosh:pushwoosh-firebase:6.6.5'


  1. Go to Firebase and create a Firebase project.


  1. Register your app with Firebase.


  1. Add a Firebase configuration file in your app.

  • You can get google-services.json file from following path in firebase console:

Go to firebase project setting and click on the google-services.json button to download.

  • Move your configuration file into the module (app-level) root directory of your app. (Under dir app/)


  1. Add Firebase SDK and plugin.

  • Add the following lines in root-level (project-level) Gradle file under dependencies section.

classpath 'com.google.gms:google-services:4.3.14'


Full code of root-level (project-level) Gradle file:

buildscript {

    repositories {

      // Make sure that you have the following two repositories

      google()  // Google's Maven repository

      mavenCentral()  // Maven Central repository

    }


    dependencies {

      // Add the dependency for the Google services Gradle plugin

      classpath 'com.google.gms:google-services:4.3.14'

    }

}


allprojects {

  ...

  repositories {

    // Make sure that you have the following two repositories

    google()  // Google's Maven repository

    mavenCentral()  // Maven Central repository

  }

}


  • Add the following lines in module (app-level) Gradle file under plugins section.


plugins {

    id 'com.android.application'


    // Add the Google services Gradle plugin

    id 'com.google.gms.google-services'

    ...

}


  • Add the firebase and push notification dependency in module (app-level) Gradle file under dependencies section.


dependencies {

      //Add the dependency for the Firebase Push Notification

      implementation 'com.google.firebase:firebase-messaging-ktx:23.1.0'

}


  1. Now, Sync the project.















  1. Add the following metadata to AndroidManifest.xml inside <application> tag:


<meta-data android:name="com.pushwoosh.appid" android:value="XXXXX-XXXXX" />

<meta-data android:name="com.pushwoosh.senderid" android:value="@string/fcm_sender_id" />



  • com.pushwoosh.appid is your Pushwoosh Application Code

  • com.pushwoosh.senderid is the Sender ID you received from Firebase Console 


  • You can get sender id from Firebase project> Project settings> Cloud messaging tab.
















Please note that you need to add fcm_sender_id to res/values/strings.xml of your Android project, Like this:

<resources>

<string name="fcm_sender_id">123456789012</string>

</resources>




  1. Register for push notifications, Add following line in your app Application class, inside onCreate() method:

Pushwoosh.getInstance().registerForPushNotifications()


class MainActivity : Application() {


    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate()

       

        Pushwoosh.getInstance().registerForPushNotifications()

    }

}

 

  • Now, Pushwoosh setup is completed.








Adjust SDK integration


  1. Add adjust library dependencies in build.gradle file under dependencies section.


 dependencies {

   implementation 'com.adjust.sdk:adjust-android:4.33.0'

   implementation 'com.android.installreferrer:installreferrer:2.2'

   implementation 'com.google.android.gms:play-services-ads-identifier:17.0.1'

}


  1. Add permissions.

  • The Adjust SDK requires the following permissions. Add them to your AndroidManifest.xml file if they are not already present:


<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>


  1. Set up Proguard.

  • If you are using Proguard in your application, add the following lines to your Proguard file:

  • Move following lines in proguard-rules.pro file, which is available in Gradle scripts.


-keep class com.adjust.sdk.** { *; }

-keep class com.google.android.gms.common.ConnectionResult {

    int SUCCESS;

}

-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {

    com.google.android.gms.ads.identifier.AdvertisingIdClient$Info getAdvertisingIdInfo(android.content.Context);

}

-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {

    java.lang.String getId();

    boolean isLimitAdTrackingEnabled();

}

-keep public class com.android.installreferrer.** { *; }







  1. Set up install referrer, Add the following code lines in AndroidManifest.xml file inside  <application> tag.


<receiver

    android:name="com.adjust.sdk.AdjustReferrerReceiver"

    android:permission="android.permission.INSTALL_PACKAGES"

    android:exported="true" >

    <intent-filter>

        <action android:name="com.android.vending.INSTALL_REFERRER" />

    </intent-filter>

</receiver>


  1. Integrate the SDK into your app.

1. Create a class that extends the Application.

2. Open the AndroidManifest.xml file and locate the <application> element.

3. Add the android:name attribute and set it to the name of your application class. For example, if your Application class is named GlobalApplication:


<application

   android:name=".GlobalApplication"

   <!-- ... -->

 </application>


4. In your Application class, find or add the onCreate method and AdjustLifecycleCallbacks class. Add the following code to initialize the Adjust SDK:


public class GlobalApplication extends Application {

    @Override

    public void onCreate() {

        super.onCreate();


        String appToken = "{YourAppToken}";

        String environment = AdjustConfig.ENVIRONMENT_SANDBOX;

        AdjustConfig config = new AdjustConfig(this, appToken, environment);

        Adjust.onCreate(config);


        registerActivityLifecycleCallbacks(new AdjustLifecycleCallbacks());

    }


class AdjustLifecycleCallbacks : Application.ActivityLifecycleCallbacks {

    override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {

    }


    override fun onActivityStarted(activity: Activity) {

    }


    override fun onActivityResumed(activity: Activity) {

        Adjust.onResume()

    }


    override fun onActivityPaused(activity: Activity) {

        Adjust.onPause()

    }


    override fun onActivityStopped(activity: Activity) {

    }


    override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {

    }


    override fun onActivityDestroyed(activity: Activity) {

    }

}


}


Tip: You can find your app token in your Adjust dashboard.



  1. Set the environment variable to either sandbox or production mode.


Important: 

When running tests you should ensure that your environment is set to AdjustConfig.ENVIRONMENT_SANDBOX. Change this to AdjustConfig.ENVIRONMENT_PRODUCTION before you submit your application to the App Store.


String environment = AdjustConfig.ENVIRONMENT_SANDBOX;

String environment = AdjustConfig.ENVIRONMENT_PRODUCTION;


  1. Build your app.




Customize Pooshwoosh Notifications


For, Getting custom data from pushwoosh notification follow the below steps.


  1. Add the following class which extends NotificationServiceExtension.


public class MyNotificationServiceExtension extends NotificationServiceExtension {

    @Override

    protected void startActivityForPushMessage(PushMessage message) {

      // super.startActivityForPushMessage() starts default launcher activity 

      // or activity marked with ${applicationId}.MESSAGE action.

      // Simply do not call it to override this behaviour.

        // super.startActivityForPushMessage(message);

        

        boolean isPromoAction = false;

        try {

            JSONObject jsonObject = new JSONObject(message.getCustomData());

            if (jsonObject.has("pushwoosh"))

            {

                if (jsonObject.getString("pushwoosh").equals("promo"))

                {

                    isPromoAction = true;

                }

            }

        } catch (JSONException e) {

            e.printStackTrace();

        }


        // start your activity instead:

        Intent launchIntent;

        if (isPromoAction) {

            launchIntent = new Intent(getApplicationContext(), SuperSaleActivity.class);

        } else {

            launchIntent  = new Intent(getApplicationContext(), reliance.class);

        }         

        launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

        getApplicationContext().startActivity(launchIntent);

    }

}




  • In the above code, “pushwoosh” is a custom key which is defined in the pushwoosh dashboard.

  • Get value from custom key like this:

jsonObject.getString("pushwoosh")


  1. Add meta-data in AndroidMenifest.xml file.

<meta-data 

android:name="com.pushwoosh.notification_service_extension"

            android:value="com.soiloker.streetview.MyNotificationServiceExtension" />


  1. Log the subscription event in Adjust SDK.

- Add the following lines inside the onPurchasesUpdated() method of Google In-app purchase.


skuDetail?.let { skuD->                       Constant.logSubscriptionEvent(skuD.priceAmountMicros,skuD.priceCurrencyCode,skuD.sku,purchase.orderId,purchase.signature,purchase.purchaseToken,purchase.purchaseTime)    }

          Constant.pushWooshTagsForSubscription(true)


- Create a class named Constant.kt and add the following method inside Constant.kt class.


fun logSubscriptionEvent(price:Long,currency:String,sku:String ,orderId:String,signature:String,purchaseToken:String,purchaseTime:Long)

    {

        val subscription = AdjustPlayStoreSubscription(

            price,

            currency,

            sku,

            orderId,

            signature,

            purchaseToken

        )

        subscription.purchaseTime = purchaseTime

        Adjust.trackPlayStoreSubscription(subscription)

    }

  }


fun adjustEvent(eventName: String) {

        Adjust.trackEvent(AdjustEvent(eventName))

    }


    fun pushWooshTagsForSubscription(tag: Boolean) {

        Pushwoosh.getInstance().setTags(Tags.booleanTag("SubscriptionPurchased", tag))

    }

Events Needs to be logged with Adjust

Event Names


const val ADJUST_EXIT_SUB_EVENT = "" // when user click on cross icon in Nomral subscription screen


const val ADJUST_NOTIFICATION_SHOWED_EVENT = "" //when we show notification

const val ADJUST_NOTIFICATION_CLICKED_EVENT = ""  // when user click on notification 


const val ADJUST_DISCOUNT_EXIT_EVENT = "" // when user click on cross icon in Special subscription screen


const val ADJUST_DISCOUNT_PROMO_PAY = "" // when user click on purchase in Special subscription screen