|
| 1 | +package convertedin.pixel.pixelsdk |
| 2 | + |
| 3 | +import android.content.Context |
| 4 | +import android.util.Log |
| 5 | +import convertedin.pixel.pixelsdk.data.entities.EventContent |
| 6 | +import convertedin.pixel.pixelsdk.utils.PixelHelper |
| 7 | + |
| 8 | +class ConvertedInSdk { |
| 9 | + |
| 10 | + |
| 11 | + companion object { |
| 12 | + var apiUrl: String = "https://test.convertedin.com/api/" |
| 13 | + private var sInstance: ConvertedInSdk? = null |
| 14 | + private var helper: PixelHelper? = null |
| 15 | + |
| 16 | + private fun getInstance(context: Context) : ConvertedInSdk { |
| 17 | + if (sInstance == null) { |
| 18 | + sInstance = ConvertedInSdk() |
| 19 | + if (helper == null) |
| 20 | + helper = PixelHelper(context) |
| 21 | + |
| 22 | + } |
| 23 | + return sInstance!! |
| 24 | + } |
| 25 | + |
| 26 | + } |
| 27 | + |
| 28 | + //initialize SDK, pixel id and store url |
| 29 | + //u can obtain these data from converted in dashboard |
| 30 | + fun initialize(context: Context, pixelId: String, storeUrl: String) { |
| 31 | + getInstance(context) |
| 32 | + helper?.saveData(pixelId, storeUrl) |
| 33 | + helper?.saveDeviceId() |
| 34 | + Log.d("Pixel SDK", "$apiUrl$pixelId") |
| 35 | + } |
| 36 | + |
| 37 | + //identify user to get customer id |
| 38 | + fun identifyUser( |
| 39 | + email: String? = "", |
| 40 | + phone: String? = "", |
| 41 | + countryCode: String? = "" |
| 42 | + ) { |
| 43 | + if (email.isNullOrEmpty() && |
| 44 | + phone.isNullOrEmpty() && |
| 45 | + countryCode.isNullOrEmpty() |
| 46 | + ) { |
| 47 | + Log.e("pixel sdk error", "error, provide data for identity") |
| 48 | + } else |
| 49 | + helper?.identifyUser(email, if (countryCode.isNullOrEmpty()) null else phone, countryCode) |
| 50 | + } |
| 51 | + |
| 52 | + |
| 53 | + // add any event |
| 54 | + fun addEvent( |
| 55 | + eventName: String, |
| 56 | + currency: String?, |
| 57 | + total: String?, |
| 58 | + products: ArrayList<EventContent>? |
| 59 | + ) { |
| 60 | + helper?.addEvent(eventName, currency, total, products) |
| 61 | + } |
| 62 | + |
| 63 | + // add view content event |
| 64 | + fun viewContentEvent( |
| 65 | + currency: String?, |
| 66 | + total: String?, |
| 67 | + products: ArrayList<EventContent>? |
| 68 | + ) { |
| 69 | + helper?.viewContentEvent(currency, total, products) |
| 70 | + } |
| 71 | + |
| 72 | + // add view page event |
| 73 | + fun pageViewEvent( |
| 74 | + currency: String?, |
| 75 | + total: String?, |
| 76 | + products: ArrayList<EventContent>? |
| 77 | + ) { |
| 78 | + helper?.pageViewEvent(currency, total, products) |
| 79 | + } |
| 80 | + |
| 81 | + // add to cart event |
| 82 | + fun addToCartEvent( |
| 83 | + currency: String?, |
| 84 | + total: String?, |
| 85 | + products: ArrayList<EventContent>? |
| 86 | + ) { |
| 87 | + helper?.addToCartEvent(currency, total, products) |
| 88 | + } |
| 89 | + |
| 90 | + // add init checkout event |
| 91 | + fun initiateCheckoutEvent( |
| 92 | + currency: String?, |
| 93 | + total: String?, |
| 94 | + products: ArrayList<EventContent>? |
| 95 | + ) { |
| 96 | + helper?.initiateCheckoutEvent(currency, total, products) |
| 97 | + } |
| 98 | + |
| 99 | + // add purchase event |
| 100 | + fun purchaseEvent( |
| 101 | + currency: String?, |
| 102 | + total: String?, |
| 103 | + products: ArrayList<EventContent>? |
| 104 | + ) { |
| 105 | + helper?.purchaseEvent(currency, total, products) |
| 106 | + } |
| 107 | + |
| 108 | + // add device id |
| 109 | + fun saveDeviceToken(token: String) { |
| 110 | + helper?.saveDeviceToken(token) |
| 111 | + } |
| 112 | + |
| 113 | + // delete token |
| 114 | + fun deleteDeviceToken() { |
| 115 | + helper?.deleteDeviceToken() |
| 116 | + } |
| 117 | + |
| 118 | + |
| 119 | +} |
0 commit comments