Ad fixes and appsflyer
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35549bb5a76474e7c9927233413facfd
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.darkmatter.logrocket">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<application />
|
||||
</manifest>
|
||||
</content>
|
||||
</invoke>
|
||||
@@ -0,0 +1,4 @@
|
||||
target=android-34
|
||||
android.library=true
|
||||
</content>
|
||||
</invoke>
|
||||
@@ -0,0 +1,160 @@
|
||||
package com.darkmatter.logrocket;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Thin Unity-facing wrapper around the LogRocket Android SDK.
|
||||
*
|
||||
* The LogRocket native SDK API surface is reached via reflection so the Unity
|
||||
* project will compile even if the LogRocket Maven artifact has not been added
|
||||
* yet. To enable, drop the LogRocket AAR into Plugins/Android (or add the
|
||||
* Maven coordinate to mainTemplate.gradle) and the calls below resolve at
|
||||
* runtime.
|
||||
*
|
||||
* Expected LogRocket SDK class: com.logrocket.core.LogRocket
|
||||
* static void init(android.content.Context, String appId)
|
||||
* static void identify(String userId, java.util.Map traits)
|
||||
* static void track(String name, java.util.Map properties)
|
||||
* static void log(String severity, String message)
|
||||
* static String getSessionURL()
|
||||
*/
|
||||
public final class LogRocketUnityBridge {
|
||||
private static final String TAG = "LogRocketBridge";
|
||||
private static final String LR_CLASS = "com.logrocket.core.LogRocket";
|
||||
|
||||
private static LogRocketUnityBridge INSTANCE;
|
||||
|
||||
private Class<?> lrClass;
|
||||
private boolean replayActive;
|
||||
|
||||
public static synchronized LogRocketUnityBridge getInstance() {
|
||||
if (INSTANCE == null) INSTANCE = new LogRocketUnityBridge();
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void init(Activity activity, String appId) {
|
||||
try {
|
||||
lrClass = Class.forName(LR_CLASS);
|
||||
lrClass.getMethod("init", android.content.Context.class, String.class)
|
||||
.invoke(null, activity.getApplicationContext(), appId);
|
||||
Log.i(TAG, "LogRocket initialised: " + appId);
|
||||
} catch (ClassNotFoundException notFound) {
|
||||
Log.e(TAG, "LogRocket SDK class not found. Add the LogRocket Android dependency.");
|
||||
lrClass = null;
|
||||
} catch (Throwable t) {
|
||||
Log.e(TAG, "LogRocket init failed", t);
|
||||
lrClass = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void identify(String userId, String traitsJson) {
|
||||
if (lrClass == null) return;
|
||||
try {
|
||||
Map<String, Object> traits = parse(traitsJson);
|
||||
lrClass.getMethod("identify", String.class, Map.class).invoke(null, userId, traits);
|
||||
} catch (Throwable t) {
|
||||
Log.e(TAG, "identify failed", t);
|
||||
}
|
||||
}
|
||||
|
||||
public void track(String name, String propsJson) {
|
||||
if (lrClass == null) return;
|
||||
try {
|
||||
Map<String, Object> props = parse(propsJson);
|
||||
lrClass.getMethod("track", String.class, Map.class).invoke(null, name, props);
|
||||
} catch (Throwable t) {
|
||||
Log.e(TAG, "track failed", t);
|
||||
}
|
||||
}
|
||||
|
||||
public void log(String severity, String message) {
|
||||
if (lrClass == null) return;
|
||||
try {
|
||||
lrClass.getMethod("log", String.class, String.class).invoke(null, severity, message);
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
Log.i(TAG, "[" + severity + "] " + message);
|
||||
} catch (Throwable t) {
|
||||
Log.e(TAG, "log failed", t);
|
||||
}
|
||||
}
|
||||
|
||||
public void logException(String message, String stack) {
|
||||
if (lrClass == null) return;
|
||||
try {
|
||||
lrClass.getMethod("captureException", String.class, String.class).invoke(null, message, stack);
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
log("error", message + "\n" + stack);
|
||||
} catch (Throwable t) {
|
||||
Log.e(TAG, "logException failed", t);
|
||||
}
|
||||
}
|
||||
|
||||
public void captureFrame(byte[] jpeg, int width, int height) {
|
||||
if (lrClass == null || jpeg == null) return;
|
||||
try {
|
||||
lrClass.getMethod("captureFrame", byte[].class, int.class, int.class)
|
||||
.invoke(null, jpeg, width, height);
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
// SDK does not expose frame ingest; ignore silently.
|
||||
} catch (Throwable t) {
|
||||
Log.e(TAG, "captureFrame failed", t);
|
||||
}
|
||||
}
|
||||
|
||||
public void startReplay() {
|
||||
replayActive = true;
|
||||
if (lrClass == null) return;
|
||||
try {
|
||||
lrClass.getMethod("startCapture").invoke(null);
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
} catch (Throwable t) {
|
||||
Log.e(TAG, "startReplay failed", t);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopReplay() {
|
||||
replayActive = false;
|
||||
if (lrClass == null) return;
|
||||
try {
|
||||
lrClass.getMethod("stopCapture").invoke(null);
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
} catch (Throwable t) {
|
||||
Log.e(TAG, "stopReplay failed", t);
|
||||
}
|
||||
}
|
||||
|
||||
public String getSessionUrl() {
|
||||
if (lrClass == null) return null;
|
||||
try {
|
||||
Object url = lrClass.getMethod("getSessionURL").invoke(null);
|
||||
return url == null ? null : url.toString();
|
||||
} catch (Throwable t) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, Object> parse(String json) {
|
||||
Map<String, Object> out = new HashMap<>();
|
||||
if (json == null || json.isEmpty()) return out;
|
||||
try {
|
||||
JSONObject obj = new JSONObject(json);
|
||||
Iterator<String> it = obj.keys();
|
||||
while (it.hasNext()) {
|
||||
String k = it.next();
|
||||
out.put(k, obj.get(k));
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
Log.w(TAG, "json parse failed: " + json);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
</content>
|
||||
</invoke>
|
||||
105
Assets/Plugins/iOS/LogRocketUnityBridge.mm
Normal file
105
Assets/Plugins/iOS/LogRocketUnityBridge.mm
Normal file
@@ -0,0 +1,105 @@
|
||||
// Unity to LogRocket iOS bridge.
|
||||
//
|
||||
// Uses __has_include so this file compiles whether or not the LogRocket pod is
|
||||
// integrated. When the pod is present the real, type-checked SDK calls compile
|
||||
// in; when absent every entry point degrades to a no-op so non-LogRocket builds
|
||||
// still link.
|
||||
//
|
||||
// To enable: add `pod 'LogRocket'` to the generated Podfile (or an EDM4U
|
||||
// *Dependencies.xml), run pod install, rebuild. API verified against the
|
||||
// LogRocket iOS SDK 3.x Objective-C surface (docs.logrocket.com/reference/ios):
|
||||
// LROSDK, LROConfiguration, LROCustomEventBuilder.
|
||||
//
|
||||
// NOTE: the LogRocket SDK is a Swift framework; its objects are ARC-managed.
|
||||
// Compile this file with ARC (-fobjc-arc). Unity's generated project enables
|
||||
// ARC by default; if you see leaks, confirm the flag on this file.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#if __has_include(<LogRocket/LogRocket-Swift.h>)
|
||||
#import <LogRocket/LogRocket-Swift.h>
|
||||
#define LR_AVAILABLE 1
|
||||
#else
|
||||
#define LR_AVAILABLE 0
|
||||
#endif
|
||||
|
||||
static NSString* NSStr(const char* s) { return s ? [NSString stringWithUTF8String:s] : @""; }
|
||||
|
||||
static NSDictionary* ParseJson(const char* json) {
|
||||
if (!json) return @{};
|
||||
NSData* data = [NSStr(json) dataUsingEncoding:NSUTF8StringEncoding];
|
||||
if (!data) return @{};
|
||||
id obj = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
|
||||
return [obj isKindOfClass:[NSDictionary class]] ? obj : @{};
|
||||
}
|
||||
|
||||
// Cached session URL. getSessionURL: is asynchronous and its handler may run on
|
||||
// a background thread, so we cache the latest value and hand the C# side a
|
||||
// snapshot. The first read may be NULL until the callback resolves.
|
||||
static NSString* gSessionUrl = nil;
|
||||
|
||||
extern "C" {
|
||||
|
||||
void _lr_init(const char* appId) {
|
||||
#if LR_AVAILABLE
|
||||
LROConfiguration* cfg = [[LROConfiguration alloc] initWithAppID:NSStr(appId)];
|
||||
[LROSDK initializeWithConfiguration:cfg];
|
||||
NSLog(@"[LogRocketBridge] initialized appId=%@", NSStr(appId));
|
||||
#else
|
||||
NSLog(@"[LogRocketBridge] LogRocket pod not integrated - init no-op (appId=%@)", NSStr(appId));
|
||||
#endif
|
||||
}
|
||||
|
||||
void _lr_identify(const char* userId, const char* traitsJson) {
|
||||
#if LR_AVAILABLE
|
||||
[LROSDK identifyWithUserID:NSStr(userId) userInfo:ParseJson(traitsJson)];
|
||||
#endif
|
||||
}
|
||||
|
||||
void _lr_track(const char* eventName, const char* propsJson) {
|
||||
#if LR_AVAILABLE
|
||||
LROCustomEventBuilder* builder = [[LROCustomEventBuilder alloc] init:NSStr(eventName)];
|
||||
// Property attachment uses the builder's put* API, whose exact selector names
|
||||
// are not pinned here. Events are tracked by name; wire props once the
|
||||
// installed SDK's LROCustomEventBuilder header is confirmed.
|
||||
[LROSDK track:builder];
|
||||
#endif
|
||||
}
|
||||
|
||||
void _lr_log(const char* severity, const char* message) {
|
||||
// The iOS SDK auto-captures application logs (NSLog/os_log), so emitting via
|
||||
// NSLog is enough for it to be recorded - no manual Logger call required.
|
||||
NSLog(@"[LogRocket:%@] %@", NSStr(severity), NSStr(message));
|
||||
}
|
||||
|
||||
void _lr_logException(const char* message, const char* stack) {
|
||||
NSLog(@"[LogRocket:error] %@\n%@", NSStr(message), NSStr(stack));
|
||||
}
|
||||
|
||||
void _lr_captureFrame(const void* bytes, int length, int width, int height) {
|
||||
// No-op: LogRocket iOS records the screen natively; there is no frame-ingest
|
||||
// API. Kept so the C# DllImport resolves. Disable the Unity frame loop
|
||||
// (LogRocketConfig.EnableSessionReplay = false) to avoid wasted work.
|
||||
(void)bytes; (void)length; (void)width; (void)height;
|
||||
}
|
||||
|
||||
void _lr_startReplay(void) {
|
||||
// Recording starts automatically at initialize; nothing to do here.
|
||||
}
|
||||
|
||||
void _lr_stopReplay(void) {
|
||||
#if LR_AVAILABLE
|
||||
[LROSDK shutdown];
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* _lr_sessionUrl(void) {
|
||||
#if LR_AVAILABLE
|
||||
[LROSDK getSessionURL:^(NSString* url) {
|
||||
if (url) gSessionUrl = [url copy];
|
||||
}];
|
||||
#endif
|
||||
return gSessionUrl ? [gSessionUrl UTF8String] : NULL;
|
||||
}
|
||||
|
||||
}
|
||||
2
Assets/Plugins/iOS/LogRocketUnityBridge.mm.meta
Normal file
2
Assets/Plugins/iOS/LogRocketUnityBridge.mm.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0edf11d4da08d434cbb2befd24561025
|
||||
Reference in New Issue
Block a user