Added utm content

This commit is contained in:
r.kuznetsov 2019-09-18 15:01:15 +03:00 committed by Aleksandr Zatsepin
parent 43c6041779
commit 7396a9e599
7 changed files with 68 additions and 1 deletions

View file

@ -1020,6 +1020,14 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeGetCatalogFrontend
return ToJavaString(env, bm.GetCatalog().GetFrontendUrl(static_cast<UTM>(utm)));
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeInjectCatalogUTMContent(JNIEnv * env,
jobject, jstring url, jint content)
{
return ToJavaString(env, InjectUTMContent(ToNativeString(env, url),
static_cast<UTMContent>(content)));
}
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeIsCategoryFromCatalog(
JNIEnv *, jobject, jlong catId)

View file

@ -717,6 +717,12 @@ public enum BookmarkManager
return nativeGetCatalogFrontendUrl(utm);
}
@NonNull
public String injectCatalogUTMContent(@NonNull String url, @UTM.UTMContentType int content)
{
return nativeInjectCatalogUTMContent(url, content);
}
@NonNull
public String getGuidesIds()
{
@ -929,6 +935,10 @@ public enum BookmarkManager
@NonNull
private static native String nativeGetCatalogFrontendUrl(@UTM.UTMType int utm);
@NonNull
private static native String nativeInjectCatalogUTMContent(@NonNull String url,
@UTM.UTMContentType int content);
private static native boolean nativeIsCategoryFromCatalog(long catId);
private static native void nativeRequestCatalogTags();

View file

@ -24,4 +24,13 @@ public class UTM
public static final int UTM_TIPS_AND_TRICKS = 7;
public static final int UTM_BOOKING_PROMO = 8;
public static final int UTM_CROWN_BUTTON = 9;
@Retention(RetentionPolicy.SOURCE)
@IntDef({ UTM_CONTENT_DESCRIPTION, UTM_CONTENT_VIEW, UTM_CONTENT_DETAILS })
public @interface UTMContentType {}
// The order of these constants must correspond to C++ enumeration in partners_api/utm.hpp.
public static final int UTM_CONTENT_DESCRIPTION = 0;
public static final int UTM_CONTENT_VIEW = 1;
public static final int UTM_CONTENT_DETAILS = 2;
}

View file

@ -1,4 +1,4 @@
// This enumeration must correspond to C++ enumeration in partners_api/utm.hpp.
// These enumerations must correspond to C++ enumeration in partners_api/utm.hpp.
typedef NS_ENUM(NSInteger, MWMUTM) {
MWMUTMNone = 0,
MWMUTMBookmarksPageCatalogButton,
@ -11,3 +11,9 @@ typedef NS_ENUM(NSInteger, MWMUTM) {
MWMUTMBookingPromo,
MWMUTMCrownButton,
};
typedef NS_ENUM(NSInteger, MWMUTMContent) {
MWMUTMContentDescription = 0,
MWMUTMContentView,
MWMUTMContentDetails,
};

View file

@ -68,6 +68,7 @@ typedef void (^PingCompletionBlock)(BOOL success);
- (BOOL)areNotificationsEnabled;
- (NSURL * _Nullable)catalogFrontendUrl:(MWMUTM)utm;
- (NSURL * _Nullable)injectCatalogUTMContent:(NSURL * _Nullable)url content:(MWMUTMContent)content;
- (NSURL * _Nullable)catalogFrontendUrlPlusPath:(NSString *)path
utm:(MWMUTM)utm;
- (NSURL *_Nullable)deeplinkForCategoryId:(MWMMarkGroupID)groupId;

View file

@ -590,6 +590,14 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
return urlString ? [NSURL URLWithString:urlString] : nil;
}
- (NSURL * _Nullable)injectCatalogUTMContent:(NSURL * _Nullable)url content:(MWMUTMContent)content {
if (!url)
return nil;
NSString * urlString = @(InjectUTMContent(std::string(url.absoluteString.UTF8String),
(UTMContent)content).c_str());
return urlString ? [NSURL URLWithString:urlString] : nil;
}
- (NSURL * _Nullable)catalogFrontendUrlPlusPath:(NSString *)path
utm:(MWMUTM)utm
{

View file

@ -19,6 +19,13 @@ enum class UTM : uint8_t
CrownButton,
};
enum class UTMContent : uint8_t
{
Description = 0,
View,
Details,
};
inline std::string InjectUTM(std::string const & url, UTM utm)
{
base::url::Params params;
@ -66,3 +73,21 @@ inline std::string InjectUTM(std::string const & url, UTM utm)
}
return base::url::Make(url, params);
}
inline std::string InjectUTMContent(std::string const & url, UTMContent content)
{
base::url::Params params;
switch (content)
{
case UTMContent::Description:
params.emplace_back("utm_content", "description");
break;
case UTMContent::View:
params.emplace_back("utm_content", "view");
break;
case UTMContent::Details:
params.emplace_back("utm_content", "details");
break;
}
return base::url::Make(url, params);
}