更新ThinkingData Package
parent
ea822121f8
commit
33379a741d
|
|
@ -1,140 +0,0 @@
|
|||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
|
||||
namespace ThinkingData.Analytics.Editors
|
||||
{
|
||||
[CustomEditor(typeof(TDAnalytics))]
|
||||
[CanEditMultipleObjects]
|
||||
public class TD_Inspectors : Editor
|
||||
{
|
||||
private ReorderableList _stringArray;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
|
||||
var appId = this.serializedObject.FindProperty("configs");
|
||||
|
||||
_stringArray = new ReorderableList(appId.serializedObject, appId, true, true, true, true)
|
||||
{
|
||||
drawHeaderCallback = DrawListHeader,
|
||||
drawElementCallback = DrawListElement,
|
||||
onRemoveCallback = RemoveListElement,
|
||||
onAddCallback = AddListElement
|
||||
};
|
||||
|
||||
_stringArray.elementHeight = 5 * (EditorGUIUtility.singleLineHeight + 10);
|
||||
|
||||
_stringArray.serializedProperty.isExpanded = true;
|
||||
}
|
||||
|
||||
void DrawListHeader(Rect rect)
|
||||
{
|
||||
var arect = rect;
|
||||
arect.height = EditorGUIUtility.singleLineHeight + 10;
|
||||
arect.x += 14;
|
||||
arect.width = 80;
|
||||
GUIStyle style = new GUIStyle();
|
||||
style.fontStyle = FontStyle.Bold;
|
||||
|
||||
GUI.Label(arect, "Instance Configurations", style);
|
||||
}
|
||||
|
||||
void DrawListElement(Rect rect, int index, bool isActive, bool isFocused)
|
||||
{
|
||||
var spacing = 5;
|
||||
var xSpacing = 85;
|
||||
var arect = rect;
|
||||
SerializedProperty item = _stringArray.serializedProperty.GetArrayElementAtIndex(index);
|
||||
var serElem = this._stringArray.serializedProperty.GetArrayElementAtIndex(index);
|
||||
arect.height = EditorGUIUtility.singleLineHeight;
|
||||
arect.width = 240;
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
EditorGUI.PropertyField(arect, item, new GUIContent((index + 1) + " (default)"));
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.PropertyField(arect, item, new GUIContent("" + (index + 1)));
|
||||
|
||||
}
|
||||
arect.y += EditorGUIUtility.singleLineHeight + spacing;
|
||||
GUIStyle style = new GUIStyle();
|
||||
style.fontStyle = FontStyle.Bold;
|
||||
|
||||
|
||||
EditorGUI.LabelField(arect, "APP ID:", style);
|
||||
arect.x += xSpacing;
|
||||
EditorGUI.PropertyField(arect, serElem.FindPropertyRelative("appId"), GUIContent.none);
|
||||
|
||||
arect.y += EditorGUIUtility.singleLineHeight + spacing;
|
||||
arect.x -= xSpacing;
|
||||
|
||||
EditorGUI.LabelField(arect, "SERVER URL:", style);
|
||||
arect.x += xSpacing;
|
||||
EditorGUI.PropertyField(new Rect(arect.x, arect.y, arect.width, arect.height), serElem.FindPropertyRelative("serverUrl"), GUIContent.none);
|
||||
|
||||
arect.y += EditorGUIUtility.singleLineHeight + spacing;
|
||||
arect.x -= xSpacing;
|
||||
|
||||
EditorGUI.LabelField(arect, "MODE:", style);
|
||||
arect.x += xSpacing;
|
||||
EditorGUI.PropertyField(arect, serElem.FindPropertyRelative("mode"), GUIContent.none);
|
||||
|
||||
arect.y += EditorGUIUtility.singleLineHeight + spacing;
|
||||
arect.x -= xSpacing;
|
||||
|
||||
EditorGUI.LabelField(arect, "TimeZone:", style);
|
||||
arect.x += xSpacing;
|
||||
var a = serElem.FindPropertyRelative("timeZone");
|
||||
if (a.intValue == 100)
|
||||
{
|
||||
EditorGUI.PropertyField(new Rect(arect.x, arect.y, 115, arect.height), a, GUIContent.none);
|
||||
arect.x += 125;
|
||||
EditorGUI.PropertyField(new Rect(arect.x, arect.y, 115, arect.height), serElem.FindPropertyRelative("timeZoneId"), GUIContent.none);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.PropertyField(arect, a, GUIContent.none);
|
||||
}
|
||||
}
|
||||
|
||||
void AddListElement(ReorderableList list)
|
||||
{
|
||||
if (list.serializedProperty != null)
|
||||
{
|
||||
list.serializedProperty.arraySize++;
|
||||
list.index = list.serializedProperty.arraySize - 1;
|
||||
SerializedProperty item = list.serializedProperty.GetArrayElementAtIndex(list.index);
|
||||
item.FindPropertyRelative("appId").stringValue = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
ReorderableList.defaultBehaviours.DoAddButton(list);
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveListElement(ReorderableList list)
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Warnning", "Do you want to remove this element?", "Remove", "Cancel"))
|
||||
{
|
||||
ReorderableList.defaultBehaviours.DoRemoveButton(list);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
this.serializedObject.Update();
|
||||
var property = _stringArray.serializedProperty;
|
||||
property.isExpanded = EditorGUILayout.Foldout(property.isExpanded, property.displayName);
|
||||
if (property.isExpanded)
|
||||
{
|
||||
|
||||
_stringArray.DoLayoutList();
|
||||
}
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9e175a5169e2c4de78d15b28f2ce6520
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,124 +0,0 @@
|
|||
#if UNITY_EDITOR && UNITY_IOS
|
||||
using System.IO;
|
||||
using ThinkingData.Analytics.Utils;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEditor.iOS.Xcode;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ThinkingData.Analytics.Editors
|
||||
{
|
||||
public class TD_PostProcessBuild
|
||||
{
|
||||
//Xcode Build Settings
|
||||
//[PostProcessBuild]
|
||||
[PostProcessBuildAttribute(88)]
|
||||
public static void OnPostProcessBuild(BuildTarget target, string targetPath)
|
||||
{
|
||||
if (target != BuildTarget.iOS)
|
||||
{
|
||||
Debug.LogWarning("[ThinkingData] Warning: Target is not iOS. XCodePostProcess will not run");
|
||||
return;
|
||||
}
|
||||
|
||||
string projPath = Path.GetFullPath(targetPath) + "/Unity-iPhone.xcodeproj/project.pbxproj";
|
||||
|
||||
PBXProject proj = new PBXProject();
|
||||
proj.ReadFromFile(projPath);
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
string targetGuid = proj.GetUnityFrameworkTargetGuid();
|
||||
#else
|
||||
string targetGuid = proj.TargetGuidByName(PBXProject.GetUnityTargetName());
|
||||
#endif
|
||||
|
||||
//Build Property
|
||||
proj.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");//BitCode NO
|
||||
proj.SetBuildProperty(targetGuid, "GCC_ENABLE_OBJC_EXCEPTIONS", "YES");//Enable Objective-C Exceptions
|
||||
proj.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-ObjC");
|
||||
|
||||
string[] headerSearchPathsToAdd = { "$(SRCROOT)/Libraries/Plugins/iOS/ThinkingSDK/Source/main", "$(SRCROOT)/Libraries/Plugins/iOS/ThinkingSDK/Source/common" };
|
||||
proj.UpdateBuildProperty(targetGuid, "HEADER_SEARCH_PATHS", headerSearchPathsToAdd, null);// Header Search Paths
|
||||
|
||||
//Add Frameworks
|
||||
proj.AddFrameworkToProject(targetGuid, "WebKit.framework", true);
|
||||
proj.AddFrameworkToProject(targetGuid, "CoreTelephony.framework", true);
|
||||
proj.AddFrameworkToProject(targetGuid, "SystemConfiguration.framework", true);
|
||||
proj.AddFrameworkToProject(targetGuid, "Security.framework", true);
|
||||
proj.AddFrameworkToProject(targetGuid, "UserNotifications.framework", true);
|
||||
|
||||
//Add Lib
|
||||
proj.AddFileToBuild(targetGuid, proj.AddFile("usr/lib/libsqlite3.tbd", "libsqlite3.tbd", PBXSourceTree.Sdk));
|
||||
proj.AddFileToBuild(targetGuid, proj.AddFile("usr/lib/libz.tbd", "libz.tbd", PBXSourceTree.Sdk));
|
||||
|
||||
proj.WriteToFile(projPath);
|
||||
|
||||
//Info.plist
|
||||
//Disable preset properties
|
||||
string plistPath = Path.Combine(targetPath, "Info.plist");
|
||||
PlistDocument plist = new PlistDocument();
|
||||
plist.ReadFromFile(plistPath);
|
||||
plist.root.CreateArray("TDDisPresetProperties");
|
||||
TDPublicConfig.GetPublicConfig();
|
||||
foreach (string item in TDPublicConfig.DisPresetProperties)
|
||||
{
|
||||
plist.root["TDDisPresetProperties"].AsArray().AddString(item);
|
||||
}
|
||||
plist.WriteToFile(plistPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_OPENHARMONY
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
|
||||
namespace ThinkingData.Analytics.Editors
|
||||
{
|
||||
public class TD_PostProcessBuild
|
||||
{
|
||||
[PostProcessBuildAttribute(88)]
|
||||
public static void OnPostProcessBuild(BuildTarget target, string targetPath)
|
||||
{
|
||||
string path = Path.Combine(targetPath, "entry/oh-package.json5");
|
||||
string jsonContent = File.ReadAllText(path);
|
||||
jsonContent = jsonContent.Replace("\"TDAnalytics\"", "\"@thinkingdata/analytics\"");
|
||||
File.WriteAllText(path, jsonContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_EDITOR && UNITY_ANDROID && UNITY_2019_1_OR_NEWER
|
||||
using UnityEditor;
|
||||
using UnityEditor.Android;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ThinkingData.Analytics.Editors
|
||||
{
|
||||
|
||||
class TD_PostProcessBuild : IPostGenerateGradleAndroidProject
|
||||
{
|
||||
// Copy configuration file ta_public_config.xml
|
||||
public int callbackOrder { get { return 0; } }
|
||||
public void OnPostGenerateGradleAndroidProject(string path)
|
||||
{
|
||||
// Copy configuration file ta_public_config.xml
|
||||
string desPath = path + "/../launcher/src/main/res/values/ta_public_config.xml";
|
||||
if (File.Exists(desPath))
|
||||
{
|
||||
File.Delete(desPath);
|
||||
}
|
||||
TextAsset textAsset = Resources.Load<TextAsset>("ta_public_config");
|
||||
if (textAsset != null && textAsset.bytes != null)
|
||||
{
|
||||
File.WriteAllBytes(desPath, textAsset.bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 75476b67117c64ab1a25a2b94db96dcb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -11,6 +11,7 @@ public class ThikingDataHelper : SdkHelper, IBIService
|
|||
private bool _isInit;
|
||||
private string _appId;
|
||||
private string _serverUrl;
|
||||
private string _distinctId;
|
||||
|
||||
private List<EventInfo> _tempEvent = new List<EventInfo>();
|
||||
|
||||
|
|
@ -40,12 +41,12 @@ public class ThikingDataHelper : SdkHelper, IBIService
|
|||
|
||||
// 尝试获取 DeviceId 和 DistinctId 验证初始化
|
||||
var deviceId = TDAnalytics.GetDeviceId();
|
||||
var distinctId = TDAnalytics.GetDistinctId(_appId);
|
||||
if (!string.IsNullOrEmpty(deviceId) && !string.IsNullOrEmpty(distinctId))
|
||||
_distinctId = TDAnalytics.GetDistinctId(_appId);
|
||||
if (!string.IsNullOrEmpty(deviceId) && !string.IsNullOrEmpty(_distinctId))
|
||||
{
|
||||
_isInit = true;
|
||||
DebugUtil.Log("ThinkingData 初始化成功! AppID: {0}, DeviceId: {1}, DistinctId: {2}", _appId, deviceId,
|
||||
distinctId);
|
||||
_distinctId);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -84,7 +85,7 @@ public class ThikingDataHelper : SdkHelper, IBIService
|
|||
{
|
||||
if (!_isInit)
|
||||
return;
|
||||
|
||||
|
||||
// 用户的登录唯一标识,此数据对应上报数据里的 #account_id,此时 #account_id的值为userId
|
||||
// 该方法不会上传登录事件
|
||||
TDAnalytics.Login(userId, _appId);
|
||||
|
|
@ -122,7 +123,7 @@ public class ThikingDataHelper : SdkHelper, IBIService
|
|||
{
|
||||
foreach (var tEvent in _tempEvent)
|
||||
{
|
||||
TDAnalytics.Track(tEvent.EventName, tEvent.EventParam, _appId);
|
||||
TDAnalytics.Track(tEvent.EventName, tEvent.EventParam, _appId);
|
||||
}
|
||||
|
||||
_tempEvent.Clear();
|
||||
|
|
@ -141,6 +142,25 @@ public class ThikingDataHelper : SdkHelper, IBIService
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public string GetDistinctId()
|
||||
{
|
||||
if (!_isInit)
|
||||
{
|
||||
DebugUtil.Log("ThinkingData未初始化成功, DistinctId 为空");
|
||||
return string.Empty;
|
||||
}
|
||||
try
|
||||
{
|
||||
var currentDistinctId = TDAnalytics.GetDistinctId(_appId);
|
||||
return currentDistinctId ?? string.Empty;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugUtil.LogError("ThinkingDataHelper 获取 DistinctId 失败: {0}", e);
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue