JS SDK for Telegram Mini App
- sdk-telegram-mini-app
Сonnect the script:
<script src="https://sdk.affisemmp.com/tg-mini-app.js"></script>AffiseMMP.init({
affise_app_token: AFFISE_APP_TOKEN, // application token in affise mmp platform
})AffiseMMP.init should be called after window.onload
affise_event_name should be one from the list below
affise_parameters keys should be one from the list below
AffiseMMP.registerEvents([
{
"affise_event_name": "Order",
"affise_parameters": {
"affise_p_order_id": "23123",
"affise_p_price": "2.19",
"affise_p_quantity": 1
}
}
])"affise_p_param_01": window.Telegram?.WebApp?.initDataUnsafe?.user?.username || 'Unknown username',
"affise_p_param_02": window.Telegram?.WebApp?.initDataUnsafe?.user?.first_name || 'Unknown first_name',
"affise_p_param_03": window.Telegram?.WebApp?.initDataUnsafe?.user?.last_name || 'Unknown last_name',
"affise_p_param_04": window.Telegram?.WebApp?.initDataUnsafe?.user?.language_code || 'Unknown language_code',AffiseMMP.sendEvent("Order", {
"affise_p_order_id": "23123",
"affise_p_price": "2.19",
"affise_p_quantity": 1
})Method AffiseMMP.checkStatus return Promise
To use this method you must have sent at least one event
AffiseMMP.checkStatus()
.then((response) => response.json())List
- AchieveLevel- AddPaymentInfo
- AddToCart
- AddToWishlist
- AdRevenue
- ClickAdv
- CompleteRegistration
- CompleteStream
- CompleteTrial
- CompleteTutorial
- Contact
- ContentItemsView
- CustomizeProduct
- DeepLinked
- Donate
- FindLocation
- InitiateCheckout
- InitiatePurchase
- InitiateStream
- Invite
- LastAttributedTouch
- Lead
- ListView
- Login
- OpenedFromPushNotification
- Order
- OrderItemAdded
- OrderItemRemove
- OrderCancel
- OrderReturnRequest
- OrderReturnRequestCancel
- Purchase
- Rate
- ReEngage
- Reserve
- Sales
- Schedule
- Search
- Share
- SpendCredits
- StartRegistration
- StartTrial
- StartTutorial
- SubmitApplication
- Subscribe
- TravelBooking
- UnlockAchievement
- Unsubscribe
- Update
- ViewAdv
- ViewCart
- ViewContent
- ViewItem
- ViewItems
- InitialSubscription
- InitialTrial
- InitialOffer
- ConvertedTrial
- ConvertedOffer
- TrialInRetry
- OfferInRetry
- SubscriptionInRetry
- RenewedSubscription
- FailedSubscriptionFromRetry
- FailedOfferFromRetry
- FailedTrialFromRetry
- FailedSubscription
- FailedOfferise
- FailedTrial
- ReactivatedSubscription
- RenewedSubscriptionFromRetry
- ConvertedOfferFromRetry
- ConvertedTrialFromRetry
- Unsubscription
affise_p_achievement_idStringaffise_p_adrev_ad_typeStringaffise_p_brandStringaffise_p_brickStringaffise_p_campaign_idStringaffise_p_catalogue_idStringaffise_p_channel_typeStringaffise_p_cityStringaffise_p_classStringaffise_p_click_idStringaffise_p_contentStringaffise_p_content_idStringaffise_p_content_idsStringaffise_p_content_listStringaffise_p_content_nameStringaffise_p_content_typeStringaffise_p_conversion_idStringaffise_p_countryStringaffise_p_coupon_codeStringaffise_p_currencyStringaffise_p_currency_rateFloat64affise_p_customer_segmentStringaffise_p_customer_typeStringaffise_p_customer_user_idStringaffise_p_date_aDateTimeaffise_p_date_bDateTimeaffise_p_deep_linkStringaffise_p_departing_arrival_dateDateTimeaffise_p_departing_departure_dateDateTimeaffise_p_descriptionStringaffise_p_destination_aStringaffise_p_destination_bStringaffise_p_destination_listStringaffise_p_event_nameStringaffise_p_event_startDateTimeaffise_p_event_endDateTimeaffise_p_hotel_scoreInt64affise_p_latFloat64affise_p_levelInt64affise_p_longFloat64affise_p_max_rating_valueInt64affise_p_new_versionStringaffise_p_num_adultsInt64affise_p_num_childrenInt64affise_p_num_infantsInt64affise_p_old_versionStringaffise_p_order_idStringaffise_p_param_01Stringaffise_p_param_02Stringaffise_p_param_03Stringaffise_p_param_04Stringaffise_p_param_05Stringaffise_p_param_06Stringaffise_p_param_07Stringaffise_p_param_08Stringaffise_p_param_09Stringaffise_p_param_10Stringaffise_p_payment_info_availableStringaffise_p_pidStringaffise_p_preferred_neighborhoodsStringaffise_p_preferred_num_stopsInt64affise_p_preferred_price_rangeInt64affise_p_preferred_star_ratingsInt64affise_p_priceInt64affise_p_product_idStringaffise_p_product_nameStringaffise_p_purchase_currencyStringaffise_p_purchase_currency_rateFloat64affise_p_quantityInt64affise_p_rating_valueInt64affise_p_receipt_idStringaffise_p_regionStringaffise_p_registration_methodStringaffise_p_returning_arrival_dateDateTimeaffise_p_returning_departure_dateDateTimeaffise_p_revenueInt64affise_p_review_textStringaffise_p_scoreInt64affise_p_search_stringStringaffise_p_segmentStringaffise_p_statusStringaffise_p_subscription_idStringaffise_p_successStringaffise_p_suggested_destinationsStringaffise_p_suggested_hotelsStringaffise_p_travel_startDateTimeaffise_p_travel_endDateTimeaffise_p_tutorial_idStringaffise_p_user_scoreInt64affise_p_utm_campaignStringaffise_p_utm_mediumStringaffise_p_utm_sourceStringaffise_p_validatedStringaffise_p_virtual_currency_nameStringaffise_p_verticalStringaffise_p_voucher_codeString
Add to index.html following code:
<script src="https://sdk.affisemmp.com/tg-mini-app.js"></script>Example of init AffiseMMP and send event from React component:
function App() {
AffiseMMP.init({
affise_app_token: AFFISE_APP_TOKEN, // application token in affise mmp platform
})
return (
<Page />
)
}
function Page() {
const handleSendEvent = () => {
AffiseMMP.sendEvent("Order", {
"affise_p_order_id": "23123",
"affise_p_price": "2.19",
"affise_p_quantity": 1
})
}
return (
<button onClick={handleSendEvent}>Click me for send event</button>
)
}Example of init AffiseMMP and send event from Angular component:
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-example',
templateUrl: './example.component.html',
})
export class ExampleComponent implements OnInit {
@Input() dependency: any;
ngOnInit() {
AffiseMMP.init({
affise_app_token: AFFISE_APP_TOKEN, // application token in affise mmp platform
})
}
}example.component.html
<button (click)="onButtonClick()">Click me for send event</button>typescript
onButtonClick() {
AffiseMMP.sendEvent("Order", {
"affise_p_order_id": "23123",
"affise_p_price": "2.19",
"affise_p_quantity": 1
})
}Demo app DefaultEventsFactory.kt
For example, we want to track what items usually user adds to shopping cart. To send event first create it with following code
class Presenter {
fun onUserAddsItemsToCart(userData: String) {
AddToCartEvent(userData)
.send() // Send event
}
}For java use:
class Presenter {
void onUserAddsItemsToCart(String userData) {
new AddToCartEvent(userData)
.send(); // Send event
}
}With above example you can implement other events:
AchieveLevelAddPaymentInfoAddToCartAddToWishlistAdRevenueClickAdvCompleteRegistrationCompleteStreamCompleteTrialCompleteTutorialContactContentItemsViewCustomizeProductDeepLinkedDonateFindLocationInitiateCheckoutInitiatePurchaseInitiateStreamInviteLastAttributedTouchLeadListViewLoginOpenedFromPushNotificationOrderOrderItemAddedOrderItemRemoveOrderCancelOrderReturnRequestOrderReturnRequestCancelPurchaseRateReEngageReserveSalesScheduleSearchShareSpendCreditsStartRegistrationStartTrialStartTutorialSubmitApplicationSubscribeTravelBookingUnlockAchievementUnsubscribeUpdateViewAdvViewCartViewContentViewItemViewItemsInitialSubscriptionInitialTrialInitialOfferConvertedTrialConvertedOfferTrialInRetryOfferInRetrySubscriptionInRetryRenewedSubscriptionFailedSubscriptionFromRetryFailedOfferFromRetryFailedTrialFromRetryFailedSubscriptionFailedOfferiseFailedTrialReactivatedSubscriptionRenewedSubscriptionFromRetryConvertedOfferFromRetryConvertedTrialFromRetryUnsubscription
Use any of custom events if default doesn't fit your scenario:
CustomId01CustomId02CustomId03CustomId04CustomId05CustomId06CustomId07CustomId08CustomId09CustomId10
If above event functionality still limits your usecase, you can use UserCustomEvent
UserCustomEvent("MyCustomNameEvent")
.addPredefinedParameter(PredefinedString.DESCRIPTION, "best before 2029")
.addPredefinedParameter(PredefinedObject.CONTENT, JSONObject().apply {
put("collection", "Greatest Hits")
})
.send() // Send eventTo enrich your event with another dimension, you can use predefined parameters for most common cases. Add it to any event:
class Presenter {
fun onUserAddsItemsToCart(userData: String) {
AddToCartEvent(userData)
.addPredefinedParameter(PredefinedString.DESCRIPTION, "best before 2029")
.addPredefinedParameter(PredefinedObject.CONTENT, JSONObject().apply {
put("collection", "Greatest Hits")
})
.addPredefinedParameter(PredefinedListObject.CONTENT_LIST, listOf(
JSONObject().apply {
put("content", "songs, videos")
}
))
.send() // Send event
}
}For java use:
class Presenter {
void onUserAddsItemsToCart(String userData) {
JSONObject json = new JSONObject()
.put("collection", "Greatest Hits");
JSONObject jsonContent = new JSONObject()
.put("content", "songs, videos");
List<JSONObject> jsonList = Collections.singletonList(jsonContent);
new AddToCartEvent(userData, System.currentTimeMillis())
.addPredefinedParameter(PredefinedString.DESCRIPTION, "best before 2029")
.addPredefinedParameter(PredefinedFloat.PRICE, 2.19f)
.addPredefinedParameter(PredefinedObject.CONTENT, json)
.addPredefinedParameter(PredefinedListObject.CONTENT_LIST, jsonList)
.send(); // Send event
}
}In examples above PredefinedString.DESCRIPTION and PredefinedFloat.PRICE is used, but many others is available:
| PredefinedParameter | Type |
|---|---|
| PredefinedString | String |
| PredefinedLong | Long |
| PredefinedFloat | Float |
| PredefinedObject | JSONObject |
| PredefinedListObject | List<JSONObject> |
| PredefinedListString | List<String> |
ACHIEVEMENT_IDADREV_AD_TYPEBRANDBRICKCAMPAIGN_IDCATALOGUE_IDCHANNEL_TYPECITYCLASSCLICK_IDCONTENT_IDCONTENT_NAMECONTENT_TYPECONVERSION_IDCOUNTRYCOUPON_CODECURRENCYCUSTOMER_SEGMENTCUSTOMER_TYPECUSTOMER_USER_IDDEEP_LINKDESCRIPTIONDESTINATION_ADESTINATION_BDESTINATION_LISTEVENT_NAMENEW_VERSIONNETWORKOLD_VERSIONORDER_IDPARAM_01PARAM_02PARAM_03PARAM_04PARAM_05PARAM_06PARAM_07PARAM_08PARAM_09PARAM_10PAYMENT_INFO_AVAILABLEPIDPLACEMENTPREFERRED_NEIGHBORHOODSPRODUCT_IDPRODUCT_NAMEPURCHASE_CURRENCYRECEIPT_IDREGIONREGISTRATION_METHODREVIEW_TEXTSEARCH_STRINGSEGMENTSOURCESTATUSSUBSCRIPTION_IDSUCCESSSUGGESTED_DESTINATIONSSUGGESTED_HOTELSTUTORIAL_IDUNITUTM_CAMPAIGNUTM_MEDIUMUTM_SOURCEVALIDATEDVERTICALVIRTUAL_CURRENCY_NAMEVOUCHER_CODE
AMOUNTDATE_ADATE_BDEPARTING_ARRIVAL_DATEDEPARTING_DEPARTURE_DATEHOTEL_SCORELEVELMAX_RATING_VALUENUM_ADULTSNUM_CHILDRENNUM_INFANTSPREFERRED_NUM_STOPSPREFERRED_STAR_RATINGSQUANTITYRATING_VALUERETURNING_ARRIVAL_DATERETURNING_DEPARTURE_DATESCORETRAVEL_STARTTRAVEL_ENDUSER_SCOREEVENT_STARTEVENT_END
PREFERRED_PRICE_RANGEPRICEREVENUELATLONG
CONTENT
CONTENT_LIST
CONTENT_IDS