You should go through the installation guide first

Event Types

Laudspeaker supports the tracking a few different types of events.

These include default events, message events, and custom events.

Default Events

Default events are tracked everytime a user uses your brand’s app, and includes the following:

identify

We are in the process of adding:

start session

Message Events

When a user opens a push notification, or interacts with an in-app message we also track those interactions, and these events can be used in journeys to trigger messages, or in segments as additional filters.

Custom Events

You can configure the tracking of custom events in your application, that are unique or important to your business.

You can track a custom event by using the Laudspaker.fire function, which takes in an event as a parameter which is a string representing the name of your event and optionally a `payload“.

Example Implementation

Here’s an example:

import com.laudspeaker.android.Laudspeaker

class MainActivity : AppCompatActivity() {
    private var appBarConfiguration: AppBarConfiguration? = null
    private var binding: ActivityMainBinding? = null

    private val laudspeaker: Laudspeaker by inject()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        FirebaseApp.initializeApp(this)
        binding = ActivityMainBinding.inflate(
            layoutInflater
        )
        setContentView(binding!!.getRoot())
        setSupportActionBar(binding!!.toolbar)
        val navController = findNavController(this, R.id.nav_host_fragment_content_main)
        appBarConfiguration = Builder(navController.graph).build()
        setupActionBarWithNavController(this, navController, appBarConfiguration!!)

        laudspeaker.setNotificationIcon(R.drawable.ic_launcher_background)
        laudspeaker.handlePushOpened(intent)
        val identify_button = findViewById<Button>(R.id.identify_button)
        identify_button.setOnClickListener {
            val myMap: MutableMap<String, Any> = HashMap()
            myMap["time"] = System.currentTimeMillis()
            laudspeaker.identify("mahamad@laudspeaker.com", myMap)
        }
        val fire_button = findViewById<Button>(R.id.fire_button)
        fire_button.setOnClickListener {
            val myMap: MutableMap<String, Any> = HashMap()
            myMap["time"] = System.currentTimeMillis()
            println("Laudspeaker API: inside capture")
            laudspeaker.fire("hello", myMap)
        }
        val switchToggle = findViewById<Switch>(R.id.switchToggle)
        switchToggle.setOnCheckedChangeListener { buttonView, isChecked -> // Prevent the switch from changing state immediately
            buttonView.isChecked = !isChecked
            val map: MutableMap<String, Any> = HashMap()
            map["notification_preferences"] = isChecked
            laudspeaker.set(map)
            buttonView.isChecked = isChecked
        }
    }

    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        // Inflate the menu; this adds items to the action bar if it is present.
        menuInflater.inflate(R.menu.menu_main, menu)
        return true
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        val id = item.itemId
        return if (id == R.id.action_settings) {
            true
        } else super.onOptionsItemSelected(item)
    }

    override fun onSupportNavigateUp(): Boolean {
        val navController = findNavController(this, R.id.nav_host_fragment_content_main)
        return navigateUp(navController, appBarConfiguration!!) || super.onSupportNavigateUp()
    }
}