Skip to content

Commit

Permalink
Added pw tags for bookmark catalog and purchases
Browse files Browse the repository at this point in the history
  • Loading branch information
r.kuznetsov authored and beloal committed Aug 12, 2019
1 parent dedabe9 commit 915951c
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ Java_com_mapswithme_util_statistics_PushwooshHelper_nativeSendEditorEditObjectTa
{
GetPlatform().GetMarketingService().SendPushWooshTag(marketing::kEditorEditDiscovered);
}

JNIEXPORT jstring JNICALL
Java_com_mapswithme_util_statistics_PushwooshHelper_nativeGetFormattedTimestamp(JNIEnv * env, jclass thiz)
{
return jni::ToJavaString(env, GetPlatform().GetMarketingService().GetPushWooshTimestamp());
}
} // extern "C"
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.mapswithme.util.concurrency.UiThread;
import com.mapswithme.util.log.Logger;
import com.mapswithme.util.log.LoggerFactory;
import com.mapswithme.util.statistics.PushwooshHelper;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
Expand Down Expand Up @@ -164,6 +165,8 @@ private static void logToPushWoosh(@NonNull Application application, @NonNull Cu
{
app.sendPushWooshTags("Bookmarks_Guides_paid_tier", new String[] {productId});
app.sendPushWooshTags("Bookmarks_Guides_paid_title", new String[] {name});
app.sendPushWooshTags("Bookmarks_Guides_paid_date",
new String[] {PushwooshHelper.nativeGetFormattedTimestamp()});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ private void onSuccess(@NonNull Result<Void, PushwooshException> result)
public static native void nativeProcessFirstLaunch();
public static native void nativeSendEditorAddObjectTag();
public static native void nativeSendEditorEditObjectTag();
public static native @NonNull String nativeGetFormattedTimestamp();
}
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ private func logToPushWoosh(_ categoryInfo: CatalogCategoryInfo) {
} else {
pushManager!.setTags(["Bookmarks_Guides_paid_tier": categoryInfo.productId!]);
pushManager!.setTags(["Bookmarks_Guides_paid_title": categoryInfo.name]);
pushManager!.setTags(["Bookmarks_Guides_paid_date": MWMPushNotifications.formattedTimestamp()]);
}
}

Expand Down
2 changes: 2 additions & 0 deletions iphone/Maps/Core/Notifications/MWMPushNotifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void(^)(void))completionHandler;

+ (NSString *)formattedTimestamp;

@end
7 changes: 7 additions & 0 deletions iphone/Maps/Core/Notifications/MWMPushNotifications.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#import "MWMCommon.h"
#import "Statistics.h"

#include "platform/marketing_service.hpp"
#include "platform/platform.hpp"

#import "3party/Alohalytics/src/alohalytics_objc.h"

// If you have a "missing header error" here, then please run configure.sh script in the root repo
Expand Down Expand Up @@ -92,4 +95,8 @@ + (void)userNotificationCenter:(UNUserNotificationCenter *)center
withCompletionHandler:completionHandler];
}

+ (NSString *)formattedTimestamp {
return @(GetPlatform().GetMarketingService().GetPushWooshTimestamp().c_str());
}

@end
8 changes: 8 additions & 0 deletions map/purchase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ void Purchase::SetSubscriptionEnabled(SubscriptionType type, bool isEnabled)

for (auto & listener : m_listeners)
listener->OnSubscriptionChanged(type, isEnabled);

if (type == SubscriptionType::BookmarkCatalog)
{
auto const nowStr = GetPlatform().GetMarketingService().GetPushWooshTimestamp();
GetPlatform().GetMarketingService().SendPushWooshTag(isEnabled ?
marketing::kBookmarkCatalogSubscriptionEnabled :
marketing::kBookmarkCatalogSubscriptionDisabled, nowStr);
}
}

void Purchase::Validate(ValidationInfo const & validationInfo, std::string const & accessToken)
Expand Down
17 changes: 14 additions & 3 deletions platform/marketing_service.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "platform/marketing_service.hpp"

#include "base/gmtime.hpp"

namespace marketing
{

// Tags.
char const * const kMapVersionMin = "map_version_min";
char const * const kMapVersionMax = "map_version_max";
Expand All @@ -25,6 +26,8 @@ char const * const kEditorEditDiscovered = "editor_edit_discovered";
char const * const kTrafficDiscovered = "traffic_discovered";
char const * const kDiscoveryButtonDiscovered = "discovery_button_discovered";
char const * const kBookHotelOnBookingComDiscovered = "hotel_book_bcom_discovered";
char const * const kBookmarkCatalogSubscriptionEnabled = "bookmark_catalog_subscription_enabled";
char const * const kBookmarkCatalogSubscriptionDisabled = "bookmark_catalog_subscription_disabled";

// Events.
char const * const kDownloaderMapActionFinished = "Downloader_Map_action_finished";
Expand All @@ -46,7 +49,7 @@ void MarketingService::ProcessFirstLaunch()
{
// Send initial value for "discovered" tags.
using namespace marketing;
vector<string> tags =
std::vector<std::string> tags =
{
kMapDownloadDiscovered,

Expand All @@ -64,5 +67,13 @@ void MarketingService::ProcessFirstLaunch()
};

for (auto const & tag : tags)
SendPushWooshTag(tag, vector<string>{"0"});
SendPushWooshTag(tag, std::vector<std::string>{"0"});
}

std::string MarketingService::GetPushWooshTimestamp()
{
char nowStr[18]{};
auto const now = base::GmTime(time(nullptr));
strftime(nowStr, sizeof(nowStr), "%Y-%m-%d %H:%M", &now);
return std::string(nowStr);
}
19 changes: 13 additions & 6 deletions platform/marketing_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ extern char const * const kEditorEditDiscovered;
extern char const * const kTrafficDiscovered;
extern char const * const kDiscoveryButtonDiscovered;
extern char const * const kBookHotelOnBookingComDiscovered;
extern char const * const kBookmarkCatalogSubscriptionEnabled;
extern char const * const kBookmarkCatalogSubscriptionDisabled;

// Events.
extern char const * const kDownloaderMapActionFinished;
Expand All @@ -50,18 +52,23 @@ extern char const * const kKeyword;
class MarketingService
{
public:
using PushWooshSenderFn = function<void(string const & tag, vector<string> const & values)>;
using MarketingSenderFn = function<void(string const & tag, map<string, string> const & params)>;
using PushWooshSenderFn = std::function<void(std::string const & tag,
std::vector<std::string> const & values)>;
using MarketingSenderFn = std::function<void(std::string const & tag,
std::map<std::string, std::string> const & params)>;

void ProcessFirstLaunch();

void SetPushWooshSender(PushWooshSenderFn const & fn) { m_pushwooshSender = fn; }
void SendPushWooshTag(string const & tag);
void SendPushWooshTag(string const & tag, string const & value);
void SendPushWooshTag(string const & tag, vector<string> const & values);
void SendPushWooshTag(std::string const & tag);
void SendPushWooshTag(std::string const & tag, std::string const & value);
void SendPushWooshTag(std::string const & tag, std::vector<std::string> const & values);

std::string GetPushWooshTimestamp();

void SetMarketingSender(MarketingSenderFn const & fn) { m_marketingSender = fn; }
void SendMarketingEvent(string const & tag, map<string, string> const & params);
void SendMarketingEvent(std::string const & tag, std::map<std::string,
std::string> const & params);

private:
/// Callback fucntion for setting PushWoosh tags.
Expand Down
6 changes: 2 additions & 4 deletions storage/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,11 +827,9 @@ void Storage::OnMapFileDownloadFinished(HttpRequest::Status status,
{
GetPlatform().GetMarketingService().SendPushWooshTag(marketing::kMapLastDownloaded,
countryId);
char nowStr[18]{};
tm now = base::GmTime(time(nullptr));
strftime(nowStr, sizeof(nowStr), "%Y-%m-%d %H:%M", &now);
auto const nowStr = GetPlatform().GetMarketingService().GetPushWooshTimestamp();
GetPlatform().GetMarketingService().SendPushWooshTag(marketing::kMapLastDownloadedTimestamp,
std::string(nowStr));
nowStr);
}
}

Expand Down

0 comments on commit 915951c

Please sign in to comment.