Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: user analytics android with retails sdk #12

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 52 additions & 22 deletions android/src/main/java/com/ticketmasterignite/RetailSDKModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,63 @@ import android.content.Intent
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.Callback
import com.ticketmaster.discoveryapi.models.DiscoveryAbstractEntity
import com.ticketmaster.discoveryapi.models.DiscoveryEvent
import com.ticketmaster.prepurchase.action.TMPrePurchaseMenuItem
import com.ticketmaster.prepurchase.listener.TMPrePurchaseUserAnalyticsListener
import com.ticketmasterignite.retail.PrePurchaseActivity
import com.ticketmasterignite.retail.PurchaseActivity
import com.ticketmasterignite.retail.UserAnalyticsListenerSingleton

class RetailSDKModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
override fun getName() = "RetailSDK"

@ReactMethod
fun presentPrePurchaseVenue(venueId: String) {
val context = currentActivity
val intent = Intent(context, PrePurchaseActivity::class.java)
intent.putExtra("venueId", venueId)
context?.startActivity(intent)
}
private var userAnalyticsListener: TMPrePurchaseUserAnalyticsListener? = null
override fun getName() = "RetailSDK"

@ReactMethod
fun presentPrePurchaseAttraction(attractionId: String) {
val context = currentActivity
val intent = Intent(context, PrePurchaseActivity::class.java)
intent.putExtra("attractionId", attractionId)
context?.startActivity(intent)
}
@ReactMethod
fun presentPrePurchaseVenue(venueId: String) {
val context = currentActivity
val intent = Intent(context, PrePurchaseActivity::class.java)
intent.putExtra("venueId", venueId)
context?.startActivity(intent)
}

@ReactMethod
fun setupUserAnalytics(onEDPSelectedStarted: Callback, onMenuItemSelected: Callback, openURLNotSupported: Callback) {
userAnalyticsListener = object : TMPrePurchaseUserAnalyticsListener {
override fun onEDPSelectionStarted(event: DiscoveryEvent) {
onEDPSelectedStarted(event.toString())
}

override fun onMenuItemSelected(
event: DiscoveryAbstractEntity,
menuItemSelected: TMPrePurchaseMenuItem
) {
onMenuItemSelected(event, menuItemSelected)
}

@ReactMethod
fun presentPurchase(eventId: String) {
val context = currentActivity
val intent = Intent(context, PurchaseActivity::class.java)
intent.putExtra("eventId", eventId)
context?.startActivity(intent)
override fun openURLNotSupported(url: String) {
openURLNotSupported(url)
}
}

UserAnalyticsListenerSingleton.userAnalyticsListener = userAnalyticsListener
}

@ReactMethod
fun presentPrePurchaseAttraction(attractionId: String) {
val context = currentActivity
val intent = Intent(context, PrePurchaseActivity::class.java)
intent.putExtra("attractionId", attractionId)

context?.startActivity(intent)
}

@ReactMethod
fun presentPurchase(eventId: String) {
val context = currentActivity
val intent = Intent(context, PurchaseActivity::class.java)
intent.putExtra("eventId", eventId)
context?.startActivity(intent)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,49 @@ import com.ticketmaster.prepurchase.TMPrePurchaseFragmentFactory
import com.ticketmaster.prepurchase.TMPrePurchaseWebsiteConfiguration

class PrePurchaseActivity : AppCompatActivity() {
private lateinit var fragment: Fragment

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.venue_layout)

val tmPrePurchase = TMPrePurchase(
discoveryAPIKey = Config.get("apiKey"),
brandColor = Color.parseColor(Config.get("primaryColor"))
)
val venueId = intent.getStringExtra("venueId")
val attractionId = intent.getStringExtra("attractionId")

val discoveryVenue: DiscoveryAbstractEntity = if (!venueId.isNullOrEmpty()) {
DiscoveryVenue(hostID = venueId)
} else {
DiscoveryAttraction(hostID = attractionId)
}

val tmPrePurchaseWebsiteConfiguration = TMPrePurchaseWebsiteConfiguration(
discoveryVenue,
TMMarketDomain.US,
)

val bundle = tmPrePurchase.getPrePurchaseBundle(
tmPrePurchaseWebsiteConfiguration
)

val factory = TMPrePurchaseFragmentFactory(
tmPrePurchaseNavigationListener = PrePurchaseNavigationListener(
context = this,
apiKey = tmPrePurchase.discoveryAPIKey.orEmpty(),
) {
finish()
}
).apply {
supportFragmentManager.fragmentFactory = this
}
private lateinit var fragment: Fragment

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.venue_layout)

val tmPrePurchase = TMPrePurchase(
discoveryAPIKey = Config.get("apiKey"),
brandColor = Color.parseColor(Config.get("primaryColor"))
)
val venueId = intent.getStringExtra("venueId")
val attractionId = intent.getStringExtra("attractionId")

val discoveryVenue: DiscoveryAbstractEntity = if (!venueId.isNullOrEmpty()) {
DiscoveryVenue(hostID = venueId)
} else {
DiscoveryAttraction(hostID = attractionId)
}

fragment = factory.instantiatePrePurchase(ClassLoader.getSystemClassLoader()).apply {
arguments = bundle
}
val tmPrePurchaseWebsiteConfiguration = TMPrePurchaseWebsiteConfiguration(
discoveryVenue,
TMMarketDomain.US,
)

val bundle = tmPrePurchase.getPrePurchaseBundle(
tmPrePurchaseWebsiteConfiguration
)

val factory = TMPrePurchaseFragmentFactory(
tmPrePurchaseNavigationListener = PrePurchaseNavigationListener( context = this, apiKey = tmPrePurchase.discoveryAPIKey, ) {
finish()
},
tmPrePurchaseUserAnalyticsListener = UserAnalyticsListenerSingleton.userAnalyticsListener
).apply {
supportFragmentManager.fragmentFactory = this
}

supportFragmentManager.beginTransaction()
.add(R.id.venue_container, fragment)
.commit()
fragment = factory.instantiatePrePurchase(ClassLoader.getSystemClassLoader()).apply {
arguments = bundle
}

supportFragmentManager.beginTransaction()
.add(R.id.venue_container, fragment)
.commit()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.ticketmasterignite.retail

import com.ticketmaster.prepurchase.listener.TMPrePurchaseUserAnalyticsListener

object UserAnalyticsListenerSingleton {
var userAnalyticsListener: TMPrePurchaseUserAnalyticsListener? = null
}
14 changes: 14 additions & 0 deletions example/src/screens/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ const Home = () => {

const onShowPrePurchaseVenue = async () => {
try {
const onEDPSelectionStarted = () => {
console.log('do stuff here');
};
const onMenuItemSelected = () => {
console.log('do stuff here');
};
const openURLNotSupported = () => {
console.log('do stuff here');
};
await RetailSDK.setupUserAnalytics(
onEDPSelectionStarted,
onMenuItemSelected,
openURLNotSupported
);
Comment on lines +116 to +129
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the TODO logs are because we haven't decided what we'd like to do here? I guess we could change the logs to more descriptive for now anyway, eg. "in menu item selected" etc.

await RetailSDK.presentPrePurchaseVenue(Config.DEMO_VENUE_ID);
} catch (e) {
console.log('error when showing PrePurchase venue', (e as Error).message);
Expand Down
Loading