зеркало из https://github.com/microsoft/winsdkfb.git
refactored app events pull request
This commit is contained in:
Родитель
3a561b862c
Коммит
c05027de1e
|
@ -49,7 +49,7 @@ using namespace Windows::Web::Http::Headers;
|
|||
#define MultiPartContentType L"Content-Type: multipart/form-data; "
|
||||
#define MultiPartBoundary L"------------------------------fbsdk1234567890"
|
||||
#define UserAgent L"User-Agent"
|
||||
#define WinSDKFBUserAgent(version) L"winsdkfb." version
|
||||
#define WinSDKFBUserAgent(version) L"FBWinSDK." version
|
||||
#define WinSDKFBUserAgentString WinSDKFBUserAgent(WINSDKFB_VERSION)
|
||||
|
||||
FBClient::FBClient()
|
||||
|
|
|
@ -22,10 +22,6 @@
|
|||
//******************************************************************************
|
||||
#include "pch.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#define ALWAYSLOGINSTALLS 1
|
||||
#endif
|
||||
|
||||
#ifndef __NOFBAPPEVENTS__
|
||||
|
||||
#include "FacebookAppEvents.h"
|
||||
|
@ -47,49 +43,54 @@ using namespace Windows::Globalization;
|
|||
using namespace Windows::Storage;
|
||||
using namespace Windows::System::UserProfile;
|
||||
|
||||
#ifdef DEBUG
|
||||
#define ALWAYS_LOG_INSTALLS
|
||||
#endif
|
||||
|
||||
// Constants
|
||||
#define FACEBOOK_ACTIVITIES_PATH L"/activities"
|
||||
#define FACEBOOK_MOBILE_APP_INSTALL L"MOBILE_APP_INSTALL"
|
||||
#define FACEBOOK_CUSTOM_APP_EVENTS L"CUSTOM_APP_EVENTS"
|
||||
|
||||
bool FBSDKAppEvents::_useSimulator = false;
|
||||
|
||||
/*
|
||||
* To integrate install tracking for mobile app install ads,
|
||||
* call this method when the app is launched.
|
||||
*/
|
||||
void FBSDKAppEvents::ActivateApp()
|
||||
bool FBSDKAppEvents::UseSimulator::get()
|
||||
{
|
||||
FBSession^ session = FBSession::ActiveSession;
|
||||
// Try to grab the application id from session.
|
||||
String^ appId = session->FBAppId;
|
||||
|
||||
if ( appId == nullptr || appId->IsEmpty() )
|
||||
throw ref new Platform::InvalidArgumentException(SDKMessageMissingAppID);
|
||||
/*
|
||||
Install tracking should not fail or throw so here we catch
|
||||
and silently ignore most errors..
|
||||
*/
|
||||
try
|
||||
{
|
||||
create_task(FBSDKAppEvents::PublishInstall(appId));
|
||||
create_task(FBSDKAppEvents::LogActivateEvent(appId));
|
||||
}
|
||||
catch ( Platform::Exception^ ex )
|
||||
{
|
||||
#if DEBUG
|
||||
throw ex;
|
||||
#endif
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
return _useSimulator;
|
||||
}
|
||||
|
||||
bool FBSDKAppEvents::useSimulator = false;
|
||||
/*
|
||||
* Publish an install event to the Facebook graph endpoint.
|
||||
* Write the timestamp to localSettings so we only trigger this once.
|
||||
*/
|
||||
void FBSDKAppEvents::UseSimulator::set(bool value)
|
||||
{
|
||||
_useSimulator = value;
|
||||
}
|
||||
|
||||
void FBSDKAppEvents::ActivateApp()
|
||||
{
|
||||
FBSession^ session = FBSession::ActiveSession;
|
||||
// Try to grab the application id from session.
|
||||
String^ appId = session->FBAppId;
|
||||
|
||||
if (appId == nullptr || appId->IsEmpty())
|
||||
{
|
||||
throw ref new Platform::InvalidArgumentException(SDKMessageMissingAppID);
|
||||
}
|
||||
//Install tracking should not fail or throw so here we catch
|
||||
//and silently ignore most errors..
|
||||
try
|
||||
{
|
||||
create_task(FBSDKAppEvents::PublishInstall(appId));
|
||||
create_task(FBSDKAppEvents::LogActivateEvent(appId));
|
||||
}
|
||||
catch (Platform::Exception^ ex)
|
||||
{
|
||||
#if DEBUG
|
||||
throw;
|
||||
#endif
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
IAsyncAction^ FBSDKAppEvents::PublishInstall(
|
||||
String^ AppId
|
||||
|
@ -102,11 +103,10 @@ IAsyncAction^ FBSDKAppEvents::PublishInstall(
|
|||
|
||||
return create_async([=]() -> void
|
||||
{
|
||||
#if defined (DEBUG) && defined(ALWAYSLOGINSTALLS )
|
||||
if (!pingTime || true) {
|
||||
#else
|
||||
if (!pingTime ) {
|
||||
#endif
|
||||
#ifndef ALWAYS_LOG_INSTALLS
|
||||
if (!pingTime )
|
||||
#endif
|
||||
{
|
||||
create_task(FBSDKAppEvents::LogInstallEvent(AppId))
|
||||
.then([=](String^ lastAttributionResponse) -> void
|
||||
{
|
||||
|
@ -127,7 +127,7 @@ IAsyncAction^ FBSDKAppEvents::PublishInstall(
|
|||
dynamic_cast<PropertyValue^>(PropertyValue::CreateString(lastAttributionResponse))
|
||||
);
|
||||
|
||||
#ifdef _DEBUG
|
||||
#ifdef DEBUG
|
||||
String^ msg = L"Mobile App Install Response: " + lastAttributionResponse + L"\n"
|
||||
L"Mobile App Install Ping Time: " + calendar->GetDateTime() + L"\n";
|
||||
OutputDebugString(msg->Data());
|
||||
|
@ -137,66 +137,59 @@ IAsyncAction^ FBSDKAppEvents::PublishInstall(
|
|||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Logs an install event to the Facebook graph endpoint.
|
||||
* The user will be looked up using idfa or windows_attribution_id
|
||||
*/
|
||||
IAsyncOperation<String^>^ FBSDKAppEvents::LogInstallEvent(
|
||||
String^ AppId
|
||||
String^ AppId
|
||||
)
|
||||
{
|
||||
String^ path = AppId + FACEBOOK_ACTIVITIES_PATH;
|
||||
PropertySet^ parameters = ref new PropertySet();
|
||||
parameters->Insert(L"event", FACEBOOK_MOBILE_APP_INSTALL);
|
||||
parameters->Insert(L"advertiser_id", AdvertisingManager::AdvertisingId);
|
||||
parameters->Insert(
|
||||
L"advertiser_tracking_enabled",
|
||||
AdvertisingManager::AdvertisingId->IsEmpty() ? "0" : "1"
|
||||
);
|
||||
String^ path = AppId + FACEBOOK_ACTIVITIES_PATH;
|
||||
PropertySet^ parameters = ref new PropertySet();
|
||||
parameters->Insert(L"event", FACEBOOK_MOBILE_APP_INSTALL);
|
||||
parameters->Insert(L"advertiser_id", AdvertisingManager::AdvertisingId);
|
||||
parameters->Insert(
|
||||
L"advertiser_tracking_enabled",
|
||||
AdvertisingManager::AdvertisingId->IsEmpty() ? "0" : "1"
|
||||
);
|
||||
|
||||
return create_async([=]() -> task<String^>
|
||||
{
|
||||
return create_task([=]()
|
||||
{
|
||||
if (FBSDKAppEvents::UseSimulator)
|
||||
{
|
||||
return CurrentAppSimulator::GetAppPurchaseCampaignIdAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
return CurrentApp::GetAppPurchaseCampaignIdAsync();
|
||||
}
|
||||
}).then([=](task<String^> getCampaignIdTask) -> task<String^>
|
||||
{
|
||||
try
|
||||
{
|
||||
String^ campaignID = getCampaignIdTask.get();
|
||||
parameters->Insert(L"windows_attribution_id", campaignID);
|
||||
return create_task([=]() -> IAsyncOperation<String^>^
|
||||
{
|
||||
return HttpManager::Instance->PostTaskAsync(path, parameters);
|
||||
});
|
||||
}
|
||||
catch (Platform::Exception^ ex)
|
||||
{
|
||||
OutputDebugString(L"This happens when app is not yet published");
|
||||
OutputDebugString(ex->Message->Data());
|
||||
}
|
||||
|
||||
///Passing default value since we did not make network call
|
||||
return create_task([]() -> String^
|
||||
{
|
||||
OutputDebugString(L"This value must be replaced");
|
||||
//TODO: what is right default value?
|
||||
return ref new String(L"");
|
||||
});
|
||||
});
|
||||
});
|
||||
return create_async([=]() -> task<String^>
|
||||
{
|
||||
return create_task([=]()
|
||||
{
|
||||
if (FBSDKAppEvents::UseSimulator)
|
||||
{
|
||||
return CurrentAppSimulator::GetAppPurchaseCampaignIdAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
return CurrentApp::GetAppPurchaseCampaignIdAsync();
|
||||
}
|
||||
}).then([=](task<String^> getCampaignIdTask) -> task<String^>
|
||||
{
|
||||
try
|
||||
{
|
||||
String^ campaignID = getCampaignIdTask.get();
|
||||
parameters->Insert(L"windows_attribution_id", campaignID);
|
||||
return create_task([=]() -> IAsyncOperation<String^>^
|
||||
{
|
||||
return HttpManager::Instance->PostTaskAsync(path, parameters);
|
||||
});
|
||||
}
|
||||
catch (Platform::Exception^ ex)
|
||||
{
|
||||
OutputDebugString(L"This happens when app is not yet published");
|
||||
OutputDebugString(ex->Message->Data());
|
||||
}
|
||||
|
||||
// Passing default value since we did not make network call
|
||||
return create_task([]() -> String^
|
||||
{
|
||||
OutputDebugString(L"This value must be replaced");
|
||||
//TODO: what is right default value?
|
||||
return ref new String(L"");
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Logs a custom app event to the Facebook graph endpoint.
|
||||
*/
|
||||
IAsyncAction^ FBSDKAppEvents::LogActivateEvent(
|
||||
String^ AppId
|
||||
)
|
||||
|
@ -224,9 +217,6 @@ IAsyncAction^ FBSDKAppEvents::LogActivateEvent(
|
|||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates a JSON array encapsulating the activate app event
|
||||
*/
|
||||
String^ FBSDKAppEvents::GetActivateAppJson()
|
||||
{
|
||||
JsonArray^ customEvents = ref new JsonArray();
|
||||
|
|
|
@ -35,15 +35,11 @@ namespace winsdkfb
|
|||
* call this method when the app is launched.
|
||||
*/
|
||||
static void ActivateApp();
|
||||
static property bool UseSimulator {
|
||||
bool get() { return useSimulator; }
|
||||
void set(bool value)
|
||||
{
|
||||
useSimulator = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static property bool UseSimulator {
|
||||
bool get();
|
||||
void set(bool value);
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -65,7 +61,7 @@ namespace winsdkfb
|
|||
Platform::String^ AppId
|
||||
);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Logs an install event to the Facebook graph endpoint.
|
||||
* The user will be looked up using idfa or windows_attribution_id
|
||||
* @param The Application Id for the request
|
||||
|
@ -75,12 +71,13 @@ namespace winsdkfb
|
|||
Platform::String^ AppId
|
||||
);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Creates a JSON array encapsulating the activate app event
|
||||
* @return The JSON string for the event
|
||||
*/
|
||||
static Platform::String^ GetActivateAppJson();
|
||||
static bool useSimulator;
|
||||
|
||||
static bool _useSimulator;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче