Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0a84c05
Add test for Analytics SetConsent method.
jonsimantov Dec 3, 2022
7c3adde
Add std_map swig include.
jonsimantov Dec 5, 2022
03b3463
Update SWIG wrapper to create SetConsent(IDictionary)
jonsimantov Dec 5, 2022
65bd570
Add std_map.i back in.
jonsimantov Dec 6, 2022
cbf8839
Switch to regular dictionary.
jonsimantov Dec 6, 2022
ff41717
Add source upload for debugging.
jonsimantov Dec 6, 2022
3a7faaf
Set parameter type back
jonsimantov Dec 6, 2022
dc9ba37
Fix spacing and add internal class specifier.
jonsimantov Dec 6, 2022
61784ab
Add more wrapping
jonsimantov Dec 6, 2022
fc3904e
Fix
jonsimantov Dec 7, 2022
a46137d
Fix braces
jonsimantov Dec 7, 2022
3638913
Fix
jonsimantov Dec 7, 2022
d492bf8
Remove unneeded SetConsentInternal method.
jonsimantov Dec 7, 2022
bdf0479
Fix namespace
jonsimantov Dec 7, 2022
836ae94
Fix
jonsimantov Dec 8, 2022
3c417a5
Specify namespace
jonsimantov Dec 9, 2022
499b9e2
swig
jonsimantov Dec 9, 2022
6161e5d
Namespace
jonsimantov Dec 9, 2022
f10d5ef
Remove extraneous toArray
jonsimantov Dec 9, 2022
79b2118
Zip up the source first
jonsimantov Dec 9, 2022
9a420ee
Reorder.
jonsimantov Dec 9, 2022
824c638
Fix braces
jonsimantov Dec 9, 2022
5e8987a
Add missing namespace
jonsimantov Dec 9, 2022
f323ebc
Add enum tags
jonsimantov Dec 9, 2022
77703c0
Tweak namespaces
jonsimantov Dec 9, 2022
0520d4c
Move up
jonsimantov Dec 9, 2022
b39cfad
Add namespace
jonsimantov Dec 9, 2022
da43fe9
Merge branch 'main' into analytics-setconsent
a-maurice Dec 13, 2022
f34e181
Fix up the ConsentMap, and the Internal function
a-maurice Dec 14, 2022
5b3f4f8
Revert workflow.
jonsimantov Dec 14, 2022
01f17c9
Fix initialization
jonsimantov Dec 15, 2022
6997adc
Add using declaration
jonsimantov Dec 15, 2022
9a74cb4
Fix using statement
jonsimantov Dec 15, 2022
d119987
Revert "Fix using statement"
jonsimantov Dec 15, 2022
c68a0c2
Merge branch 'main' into analytics-setconsent
jonsimantov Dec 16, 2022
849d53c
Remove commented out using statements
jonsimantov Dec 17, 2022
4727b45
Merge branch 'analytics-setconsent' of https://github.com/firebase/fi…
jonsimantov Dec 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion analytics/src/swig/analytics.i
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
%{#include "app/src/export_fix.h"%}
#endif

%include "std_map.i"

%pragma(csharp) moduleclassmodifiers="public sealed class"
%pragma(csharp) modulecode=%{
// Hold a reference to the default app when methods from this module are
Expand All @@ -45,6 +47,11 @@
#include "analytics/src/include/firebase/analytics/user_property_names.h"
%}

%rename(kConsentTypeAdStorage) firebase::analytics::kConsentTypeAdStorage;
%rename(kConsentTypeAnalyticsStorage) firebase::analytics::kConsentTypeAnalyticsStorage;
%rename(kConsentStatusGranted) firebase::analytics::kConsentStatusGranted;
%rename(kConsentStatusDenied) firebase::analytics::kConsentStatusDenied;

// Constant renaming must happen before SWIG_CONSTANT_HEADERS is included.
%rename(kParameterAchievementId) firebase::analytics::kParameterAchievementID;
%rename(kParameterGroupId) firebase::analytics::kParameterGroupID;
Expand Down Expand Up @@ -231,6 +238,9 @@ class ParameterCopy : private firebase::analytics::Parameter {
// Initialize / Terminate implicitly called when App is created / destroyed.
%ignore Initialize;
%ignore Terminate;
// SetConsent handled via SetConsentInternal below.
%ignore SetConsent;

} // namespace analytics
} // namespace firebase

Expand Down Expand Up @@ -278,5 +288,49 @@ class ParameterCopy : private firebase::analytics::Parameter {
}
%}


%include "analytics/src/include/firebase/analytics.h"

%rename(ConsentType) firebase::analytics::ConsentType;
%rename(ConsentStatus) firebase::analytics::ConsentStatus;
// Add a swig C++ function to call into the Analytics C++ implementation.
%{
namespace firebase {
namespace analytics {

void SetConsentInternal(std::map<firebase::analytics::ConsentType, firebase::analytics::ConsentStatus> *ptr) {
firebase::analytics::SetConsent(*ptr);
}

} // namespace analytics
} // namespace firebase
%}
// The definition on the C++ side, so that swig is aware of the function's existence.
void SetConsentInternal(std::map<firebase::analytics::ConsentType, firebase::analytics::ConsentStatus> *ptr);

%typemap(csclassmodifiers) firebase::analytics::ConsentType "enum";
%typemap(csclassmodifiers) firebase::analytics::ConsentStatus "enum";

%typemap(csclassmodifiers) std::map<firebase::analytics::ConsentType, firebase::analytics::ConsentStatus> "internal class"
%template(ConsentMap) std::map<firebase::analytics::ConsentType, firebase::analytics::ConsentStatus>;

namespace firebase {
namespace analytics {

%pragma(csharp) modulecode=%{
/// @brief Sets the applicable end user consent state (e.g., for device
/// identifiers) for this app on this device.
///
/// Use the consent map to specify individual consent type values. Settings are
/// persisted across app sessions. By default consent types are set to
/// "granted".
public static void SetConsent(System.Collections.Generic.IDictionary<ConsentType, ConsentStatus> consentSettings) {
ConsentMap consentSettingsMap = new ConsentMap();
foreach(var kv in consentSettings) {
consentSettingsMap[kv.Key] = kv.Value;
}
SetConsentInternal(consentSettingsMap);
}
%}

} // namespace analytics
} // namespace firebase
18 changes: 18 additions & 0 deletions analytics/testapp/Assets/Firebase/Sample/Analytics/UIHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Firebase.Sample.Analytics {
using Firebase.Analytics;
using Firebase.Extensions;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;

Expand Down Expand Up @@ -121,6 +122,20 @@ public void ResetAnalyticsData() {
FirebaseAnalytics.ResetAnalyticsData();
}

public void AnalyticsSetConsent() {
FirebaseAnalytics.SetConsent(new Dictionary<ConsentType, ConsentStatus>()
{
{ ConsentType.AnalyticsStorage, ConsentStatus.Denied },
{ ConsentType.AdStorage, ConsentStatus.Denied }
});
FirebaseAnalytics.SetConsent(new Dictionary<ConsentType, ConsentStatus>());
FirebaseAnalytics.SetConsent(new Dictionary<ConsentType, ConsentStatus>()
{
{ ConsentType.AnalyticsStorage, ConsentStatus.Granted },
{ ConsentType.AdStorage, ConsentStatus.Granted }
});
}

// Get the current app instance ID.
public Task<string> DisplayAnalyticsInstanceId() {
return FirebaseAnalytics.GetAnalyticsInstanceIdAsync().ContinueWithOnMainThread(task => {
Expand Down Expand Up @@ -192,6 +207,9 @@ void GUIDisplayControls() {
if (GUILayout.Button("Show Analytics Instance ID")) {
DisplayAnalyticsInstanceId();
}
if (GUILayout.Button("Test SetConsent")) {
AnalyticsSetConsent();
}
GUILayout.EndVertical();
GUILayout.EndScrollView();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public override void Start() {
TestAnalyticsScoreDoesNotThrow,
TestAnalyticsGroupJoinDoesNotThrow,
TestAnalyticsLevelUpDoesNotThrow,
TestAnalyticsSetConsentDoesNotThrow,
TestInstanceIdChangeAfterReset,
TestResetAnalyticsData,
// Temporarily disabled until this test is deflaked. b/143603151
Expand Down Expand Up @@ -87,6 +88,12 @@ Task TestAnalyticsLevelUpDoesNotThrow() {
});
}

Task TestAnalyticsSetConsentDoesNotThrow() {
return WrapWithTask(() => {
base.AnalyticsSetConsent();
return true;
});
}
Task TestCheckAndFixDependenciesInvalidOperation() {
// Only run the test on Android, as CheckAndFixDependenciesAsync is short
// lived on other platforms, and thus could finish before the extra call.
Expand Down