Skip to content

Commit 4ec263e

Browse files
authored
Merge pull request #4 from convertedin/update-identify
update identify user function and new events (onPushNotificationClick…
2 parents 4e17d8f + 4c6bcd2 commit 4ec263e

File tree

9 files changed

+107
-33
lines changed

9 files changed

+107
-33
lines changed

PixelSDK/src/main/java/convertedin/pixel/pixelsdk/ConvertedInSdk.kt

+45-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ConvertedInSdk {
3333
helper?.saveDeviceId()
3434

3535
helper?.identifyUser()
36+
helper?.appOpened()
3637
Log.d("Pixel SDK", "$apiUrl$pixelId")
3738
}
3839

@@ -56,11 +57,27 @@ class ConvertedInSdk {
5657
helper?.addEvent(eventName, currency, total, products)
5758
}
5859

60+
/**
61+
* This event is typically triggered when a user clicks on a push notification,
62+
* and should pass the received campaign id to the function, you can find the campaign id
63+
* in the payload of the push notification ["campaign_id"] with a string value
64+
*/
65+
fun onPushNotificationClicked(campaignId: String) {
66+
helper?.clickOnPush(campaignId)
67+
}
68+
69+
/**
70+
* This event is typically triggered when a user registers for the app.
71+
*/
5972
fun registerEvent() {
6073
helper?.registerEvent()
6174
}
6275

63-
// add view content event
76+
/**
77+
* This event is typically triggered when a user views a specific piece of content,
78+
* such as a product, article, or video. By tracking ViewContent events, developers can gain
79+
* insights into what content users are engaging with most and optimize their content strategy accordingly.
80+
*/
6481
fun viewContentEvent(
6582
currency: String?,
6683
total: String?,
@@ -69,7 +86,11 @@ class ConvertedInSdk {
6986
helper?.viewContentEvent(currency, total, products)
7087
}
7188

72-
// add view page event
89+
/**
90+
* This event is triggered when a user views a page or screen within the app.
91+
* By tracking PageView events, developers can gain insights into how users navigate through
92+
* their app and optimize the user experience accordingly.
93+
*/
7394
fun pageViewEvent(
7495
currency: String?,
7596
total: String?,
@@ -78,7 +99,13 @@ class ConvertedInSdk {
7899
helper?.pageViewEvent(currency, total, products)
79100
}
80101

81-
// add to cart event
102+
/**
103+
* This event is triggered when a user adds a product to their shopping cart.
104+
* By tracking AddToCart events, developers can gain insights into which products are most
105+
* popular and optimize their product offering and pricing accordingly. The AddToCart event i
106+
* s often paired with other e-commerce events such as Purchase or Checkout events, and is an
107+
* important component of user analysis and e-commerce optimization.
108+
*/
82109
fun addToCartEvent(
83110
currency: String?,
84111
total: String?,
@@ -87,7 +114,13 @@ class ConvertedInSdk {
87114
helper?.addToCartEvent(currency, total, products)
88115
}
89116

90-
// add init checkout event
117+
/**
118+
* This event is triggered when a user begins the process of checking out and entering their
119+
* payment and shipping information. By tracking InitiateCheckout events, developers can gain
120+
* insights into how users interact with the checkout process and identify areas for improvement
121+
* to increase conversion rates. The InitiateCheckout event is often paired with other e-commerce
122+
* events such as AddToCart or Purchase events, and is an important component of user analysis and e-commerce optimization.
123+
*/
91124
fun initiateCheckoutEvent(
92125
currency: String?,
93126
total: String?,
@@ -96,7 +129,14 @@ class ConvertedInSdk {
96129
helper?.initiateCheckoutEvent(currency, total, products)
97130
}
98131

99-
// add purchase event
132+
/**
133+
*This event is triggered when a user completes a purchase and successfully makes a payment
134+
* for a product or service. By tracking Purchase events, developers can gain insights into
135+
* which products are most popular and identify patterns in user behavior to optimize the
136+
* checkout process and increase sales. The Purchase event is often paired with other e-commerce
137+
* events such as AddToCart or InitiateCheckout events, and is an important component of
138+
* user analysis and e-commerce optimization.
139+
*/
100140
fun purchaseEvent(
101141
currency: String?,
102142
total: String?,

PixelSDK/src/main/java/convertedin/pixel/pixelsdk/apis/EventApiCalls.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import io.reactivex.Single
1717
identifyRequest: IdentifyRequest
1818
): Single<IdentifyResponse> =
1919
apis.identifyUser(
20-
ConvertedInSdk.apiUrl + "v1/" + pixelId + "/" + API_IDENTITY,
20+
ConvertedInSdk.apiUrl + "v2/" + pixelId + "/" + API_IDENTITY,
2121
storeUrl,
2222
identifyRequest = identifyRequest
2323
)

PixelSDK/src/main/java/convertedin/pixel/pixelsdk/data/entities/PixelEvents.kt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ data class EventRequest(
88
@SerializedName("cuid") var cuid: String?,
99
@SerializedName("data") var data: EventData?,
1010
@SerializedName("csid") var csid: String?,
11+
@SerializedName("ca") var campaignId: String?,
1112
)
1213

1314
data class EventData(

PixelSDK/src/main/java/convertedin/pixel/pixelsdk/data/entities/PixelIdentifyUser.kt

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.google.gson.annotations.SerializedName
66
data class IdentifyRequest(
77
@SerializedName("email") var email: String? = null,
88
@SerializedName("csid") var csid: String? = null,
9+
@SerializedName("anonymous_cid") var anonymousCid: String? = null,
910
@SerializedName("phone") var phone: String? = null,
1011
@SerializedName("country_code") var countryCode: String? = null,
1112
@SerializedName("src") var src: String? = null,

PixelSDK/src/main/java/convertedin/pixel/pixelsdk/data/sharedPref/SharedPreferencesUtils.kt

+9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ class SharedPreferencesUtils private constructor(private val prefHelper: PrefHel
4646
return prefHelper.getString(DEVICE_PIXEL_ID, null)
4747
}
4848

49+
fun saveCampaignId(deviceId: String?) {
50+
prefHelper.putString(CAMPAIGN_ID, deviceId ?: "")
51+
}
52+
53+
fun getCampaignId(): String? {
54+
return prefHelper.getString(CAMPAIGN_ID, null)
55+
}
56+
4957

5058

5159
companion object {
@@ -54,6 +62,7 @@ class SharedPreferencesUtils private constructor(private val prefHelper: PrefHel
5462
const val USER = "user"
5563
const val DEVICE_TOKEN = "deviceToke"
5664
const val DEVICE_PIXEL_ID = "devicePixelId"
65+
const val CAMPAIGN_ID = "campaignId"
5766

5867
private var sharedPreferencesUtils: SharedPreferencesUtils? = null
5968

PixelSDK/src/main/java/convertedin/pixel/pixelsdk/repository/EventsRepository.kt

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@ import convertedin.pixel.pixelsdk.data.sharedPref.toObjectFromJson
99
import convertedin.pixel.pixelsdk.utils.LocalDataUtils
1010

1111

12-
class EventsRepository(private val apiCalls: EventApiCalls,
13-
private val localDataUtils: LocalDataUtils) : BaseRepository(localDataUtils) {
12+
class EventsRepository(
13+
private val apiCalls: EventApiCalls,
14+
private val localDataUtils: LocalDataUtils
15+
) : BaseRepository(localDataUtils) {
1416

1517
fun saveUser(user: IdentifyResponse) =
1618
localDataUtils.sharedPreferencesUtils.saveUser(user.toJsonString())
1719

1820
fun getUser(): IdentifyResponse? = localDataUtils.sharedPreferencesUtils.getUser()
1921
?.toObjectFromJson<IdentifyResponse>(IdentifyResponse::class.java)
2022

23+
fun saveCampaignId(campaignId: String?) =
24+
localDataUtils.sharedPreferencesUtils.saveCampaignId(campaignId)
25+
26+
fun getCampaignId() = localDataUtils.sharedPreferencesUtils.getCampaignId()
2127

2228
fun identifyUser(pixelId: String, storeUrl: String, identifyRequest: IdentifyRequest) =
2329
apiCalls.identifyUser(pixelId, storeUrl, identifyRequest = identifyRequest)

PixelSDK/src/main/java/convertedin/pixel/pixelsdk/utils/PixelHelper.kt

+33-24
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,14 @@ class PixelHelper(context: Context) {
4747
}
4848

4949
internal fun identifyUser(email: String?, phone: String?, countryCode: String?) {
50-
val csid =
51-
if (email.isNullOrBlank() && phone.isNullOrBlank() && countryCode.isNullOrBlank()) {
52-
eventsViewModel.getUser()?.csid
53-
} else {
54-
eventsViewModel.getUser()?.cid
55-
}
56-
5750
if (validUrls())
5851
eventsViewModel.identifyUser(
5952
IdentifyRequest(
6053
email = email,
6154
phone = phone,
6255
countryCode = countryCode,
63-
csid = csid,
56+
anonymousCid = eventsViewModel.getUser()?.cid,
57+
csid = eventsViewModel.getUser()?.csid,
6458
src = "push"
6559
)
6660
)
@@ -69,16 +63,20 @@ class PixelHelper(context: Context) {
6963
}
7064

7165
internal fun identifyUser() {
72-
val csid = if (eventsViewModel.getUser()?.csid.isNullOrBlank()) {
73-
null
74-
} else {
75-
eventsViewModel.getUser()?.csid
76-
}
77-
7866
if (validUrls())
7967
eventsViewModel.identifyUser(
80-
IdentifyRequest(src = "push", csid = csid)
68+
IdentifyRequest(
69+
src = "push",
70+
anonymousCid = eventsViewModel.getUser()?.cid,
71+
csid = eventsViewModel.getUser()?.csid
72+
)
8173
)
74+
saveDeviceToken(deviceToken = notificationsViewModel.getDeviceToken())
75+
}
76+
77+
internal fun appOpened() {
78+
if (validUrls())
79+
sendEvent("OpenApp", null, null, null)
8280
}
8381

8482
internal fun addEvent(
@@ -91,6 +89,13 @@ class PixelHelper(context: Context) {
9189
sendEvent(eventName, currency, total, products)
9290
}
9391

92+
internal fun clickOnPush(campaignId: String?) {
93+
if (validUrls()) {
94+
eventsViewModel.saveCampaignId(campaignId = campaignId ?: "")
95+
sendEvent("ClickOnPush", null, null, null)
96+
}
97+
}
98+
9499
internal fun registerEvent() {
95100
if (validUrls())
96101
sendEvent("Register", null, null, null)
@@ -153,7 +158,8 @@ class PixelHelper(context: Context) {
153158
event = eventName,
154159
cuid = eventsViewModel.getDeviceId(),
155160
data = EventData(currency = currency, value = total, content = products),
156-
csid = eventsViewModel.getUser()?.cid
161+
csid = eventsViewModel.getUser()?.cid,
162+
campaignId = eventsViewModel.getCampaignId()
157163
)
158164
)
159165
}
@@ -162,16 +168,19 @@ class PixelHelper(context: Context) {
162168
/////////////////////////////////////////////////////////////////////
163169

164170
internal fun saveDeviceToken(deviceToken: String?) {
165-
if (validUrls())
166-
eventsViewModel.getUser()?.cid?.let {
167-
notificationsViewModel.saveDeviceToken(
168-
SaveTokenRequest(
169-
customerId = it,
170-
deviceToken = deviceToken,
171-
tokenType = "android"
171+
if (validUrls()) {
172+
if (!deviceToken.isNullOrBlank() && deviceToken != notificationsViewModel.getDeviceToken()) {
173+
eventsViewModel.getUser()?.cid?.let {
174+
notificationsViewModel.saveDeviceToken(
175+
SaveTokenRequest(
176+
customerId = it,
177+
deviceToken = deviceToken,
178+
tokenType = "android"
179+
)
172180
)
173-
)
181+
}
174182
}
183+
}
175184
}
176185

177186

PixelSDK/src/main/java/convertedin/pixel/pixelsdk/viewmodel/EventsViewModel.kt

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ class EventsViewModel : BaseViewModel() {
4747
return repository.getUser()
4848
}
4949

50+
fun saveCampaignId(campaignId: String?) {
51+
repository.saveCampaignId(campaignId)
52+
}
53+
54+
fun getCampaignId(): String? {
55+
return repository.getCampaignId()
56+
}
57+
5058
fun identifyUser(identifyRequest: IdentifyRequest) {
5159
val storeUrl = repository.getStoreUrl()
5260
val pixelId = repository.getPixelId()

PixelSDK/src/main/java/convertedin/pixel/pixelsdk/viewmodel/NotificationsViewModel.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import convertedin.pixel.pixelsdk.repository.NotificationsRepository
3737
subscribe(
3838
repository.deleteDeviceToken(pixelId, deleteTokenRequest = deleteTokenRequest)
3939
.doAfterSuccess {
40-
repository.saveDeviceTokenLocal(null)
40+
// repository.saveDeviceTokenLocal(null) //TODO temporary 13/08/2023
4141
}, {}
4242
)
4343
}

0 commit comments

Comments
 (0)