Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions analytics/src/FirebaseAnalytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,25 @@ public static void SetUserId(string userId) {
public static void SetUserProperty(string name, string property) {
FirebaseAnalyticsInternal.SetUserProperty(name, property);
}

/// <summary>
/// Logs an in-app purchase transaction specifically for Apple's StoreKit 2.
/// </summary>
/// <remarks>
/// This method is intended for Unity developers on iOS who process transactions
/// via In-app purchases and need whish to log those purchases through Google Analytics.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is a typo in the documentation: 'need whish' should be corrected to 'wish'.

  /// via In-app purchases and wish to log those purchases through Google Analytics. 

/// The provided ID must map 1:1 with the native Apple `Transaction.id`.
/// If a matching transaction is not found in the apple devices purchase history then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Proper nouns like 'Apple' should be capitalized, and 'device's' should be possessive to correctly describe the purchase history.

  /// If a matching transaction is not found in the Apple device's purchase history then 

/// nothing will be logged to analytics.
///
/// </remarks>
/// <param name="transactionId">The native Apple transaction identifier (e.g.,
/// extracted from Unity IAP's <c>purchasedProduct.transactionID</c>).</param>
/// <returns>A Task that completes when the native StoreKit 2 transaction
/// is successfully located and logged.</returns>
public static System.Threading.Tasks.Task LogAppleTransactionAsync(string transactionId) {
return FirebaseAnalyticsInternal.LogAppleTransactionAsync(transactionId);
}
}

}
1 change: 1 addition & 0 deletions analytics/src/swig/analytics.i
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void SetConsentWithInts(const std::map<int, int>& settings) {
// GetSessionId returns Future<long long> in SWIG.
%include "app/src/swig/future.i"
%SWIG_FUTURE(Future_LongLong, long, internal, long long, FirebaseException)
%SWIG_FUTURE(FutureVoid, void, internal, void, FirebaseException)

// Ignore the Consent enums, so we can use commented ones in C#
%ignore firebase::analytics::ConsentType;
Expand Down
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 @@ -192,6 +192,21 @@ public Task<long> DisplaySessionId() {
}).Unwrap();
}

// Log a dummy Apple transaction
public Task DisplayLogAppleTransaction() {
return FirebaseAnalytics.LogAppleTransactionAsync("dummy_transaction_id").ContinueWithOnMainThread(task => {
if (task.IsCanceled) {
DebugLog("LogAppleTransaction was canceled.");
} else if (task.IsFaulted) {
DebugLog(String.Format("Encountered an error logging Apple transaction: {0}",
task.Exception.ToString()));
} else if (task.IsCompleted) {
DebugLog("LogAppleTransaction completed successfully.");
}
return task;
}).Unwrap();
}

// Output text to the debug log text field, as well as the console.
public void DebugLog(string s) {
print(s);
Expand Down Expand Up @@ -257,6 +272,9 @@ void GUIDisplayControls() {
if (GUILayout.Button("Test SetConsent")) {
AnalyticsSetConsent();
}
if (GUILayout.Button("Test LogAppleTransaction")) {
DisplayLogAppleTransaction();
}
GUILayout.EndVertical();
GUILayout.EndScrollView();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public override void Start() {
// Temporarily disabled until this test is deflaked. b/143603151
//TestCheckAndFixDependenciesInvalidOperation,
TestCheckAndFixDependenciesDoubleCall,
TestLogAppleTransaction,
};
testRunner = AutomatedTestRunner.CreateTestRunner(
testsToRun: tests,
Expand Down Expand Up @@ -254,5 +255,32 @@ Task TestResetAnalyticsData() {
});
return tcs.Task;
}

Task TestLogAppleTransaction() {
// On iOS, this should fail with a dummy ID if no simulated transaction is set up.
// On other platforms, it should be a no-op and succeed.
if (Application.platform == RuntimePlatform.IPhonePlayer) {
return base.DisplayLogAppleTransaction()
.ContinueWithOnMainThread(t => {
if (t.IsFaulted) {
DebugLog("LogAppleTransaction failed as expected with dummy ID.");
DebugLog("Exception: " + t.Exception);
return true;
} else {
DebugLog("LogAppleTransaction unexpectedly succeeded with dummy ID.");
return true;
}
});
} else {
return base.DisplayLogAppleTransaction()
.ContinueWithOnMainThread(t => {
if (t.IsFaulted) {
throw t.Exception;
}
DebugLog("LogAppleTransaction completed successfully (no-op) on this platform.");
return true;
});
}
}
}
}
29 changes: 29 additions & 0 deletions analytics/testapp/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,35 @@ Press some of the buttons to log some events to your Firebase project.
After around 5 hours, data should be visible under the *Analytics* tab in
the [Firebase Console](https://firebase.google.com/console/)).

## iOS Testing LogAppleTransaction

To test the log apple transaction function, you should use the exported Xcode project and Xcode's simulated transactions.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The method name 'LogAppleTransaction' and the proper noun 'Apple' should be capitalized for consistency and clarity.

Suggested change
To test the log apple transaction function, you should use the exported Xcode project and Xcode's simulated transactions.
To test the LogAppleTransaction function, you should use the exported Xcode project and Xcode's simulated transactions.

The manual test will involve running the testapp and verifying that it logs a transaction to the console.

- Step 1: Set up the Local Xcode Environment
- After building the sample for iOS and opening the exported project in Xcode:
- In Xcode, go to File > New > File from Template and create a StoreKit Configuration File (.storekit).
- Give the configuration any name.
- Target the `Unity-iPhone` scheme (or the relevant target for your exported app).
- Add at least one dummy product to this file.
- Do this by selecting the file in Xcode and clicking the + button in the bottom left corner.
- Choose a Consumable in app purchase product.
- Give it a Reference name of your choice (e.g. "ReferenceAppleIapProduct").
- Give it a Product ID of your choice (e.g. "com.example.nonconsumable").
- Make the app use the store kit file. In the top bar go to Product > Scheme > Edit Scheme...
- In the left hand menu select Run
- Select the Options tab on the top
- Set the StoreKit Configuration dropdown to your new .storekit file.
- Step 2: Validate logging transactions
- You can create a simulated transaction for testing.
- To create a simulated transaction ID:
- Go to Debug > StoreKit > Manage Transactions.
- Click the + button in the bottom left corner.
- Select the Consumable in app purchase product.
- Use the generated transaction ID in your code or test case.
- When you call `FirebaseAnalytics.LogAppleTransactionAsync(transactionId)` with the simulated transaction ID:
- It should log the transaction to the console. Both the Xcode console and firebase console should show a log for an in app purchase.


## Troubleshooting

Expand Down
6 changes: 6 additions & 0 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ Support

Release Notes
-------------
### Upcoming
- Changes
- Analytics: Add support for Apple's Store kit 2 transactions. Add new `LogAppleTransactionAsync` method
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The correct name for the framework is 'StoreKit 2'. Also, there is an extra space before the method name that should be removed.

Suggested change
- Analytics: Add support for Apple's Store kit 2 transactions. Add new `LogAppleTransactionAsync` method
- Analytics: Add support for Apple's StoreKit 2 transactions. Add new `LogAppleTransactionAsync` method

that takes in the App Store transaction string and logs the transaction.


### 13.11.0
- Changes
- General: Update to Firebase C++ SDK version 13.7.0.
Expand Down
Loading