「IDGraph Android Tracking Code」修訂間的差異
跳至導覽
跳至搜尋
imported>Wikiuser (新頁面: 在回報Log前,必須讓SDK進行初始化,您需要執行下列函式 IDGraphTracker.getInstance().init(Context, <PROFILE_ID>, isDebug); :第一個參數為Context :第二個參...) |
imported>Wikiuser |
||
行 4: | 行 4: | ||
:第二個參數請填入你的Profile ID (可向您的TAMedia窗口詢問) | :第二個參數請填入你的Profile ID (可向您的TAMedia窗口詢問) | ||
:第三個為boolean值,設為true時,每次回報會出現Toast訊息框以確認回報是否成功 | :第三個為boolean值,設為true時,每次回報會出現Toast訊息框以確認回報是否成功 | ||
<br> | <br> | ||
若要進行回報,需呼叫下列函式 | 若要進行回報,需呼叫下列函式 | ||
行 16: | 行 15: | ||
public class MainActivity extends AppCompatActivity { | public class MainActivity extends AppCompatActivity { | ||
private static final String PROFILE_ID = "<Your Profile ID>"; | private static final String PROFILE_ID = "<b><Your Profile ID></b>"; | ||
private static final boolean isDebug = false; | private static final boolean isDebug = false; | ||
行 31: | 行 30: | ||
Other Code ... | Other Code ... | ||
} | } | ||
<br> | |||
*<big><u>With Application Class</u></big> | |||
:若APP專案有自己的Application class,可將追蹤碼放在此class,由於Application的執行時間是在Activity啟動前,因此會比Without Application Class更早回報,但是<span style="color:red;">如果APP是透過Back鍵關掉的話,由於Application還會留在系統一小段時間, 導致使用者短時間內再次打開APP時並不會觸發回報</span>, 必須等待系統將其回收或是使用者自行把APP刷掉(在桌面點選Menu Button, 再將APP上滑關閉), Application才算是真正結束<br> | |||
<br> | |||
:程式碼如下:<br> | |||
<b><MyCustomApplication.java></b> | |||
public class MyCustomApplication extends Application { | |||
private static final String PROFILE_ID = "<b><Your Profile ID></b>"; | |||
private static final boolean isDebug = false; | |||
// Called when the application is starting, before any other application objects have been created. | |||
// Overriding this method is totally optional! | |||
@Override | |||
public void onCreate() { | |||
super.onCreate(); | |||
// Initial | |||
IDGraphTracker.getInstance().init(this, PROFILE_ID, isDebug); | |||
// Send Tracking Log | |||
IDGraphTracker.getInstance().reportTrackLog(); | |||
} | |||
Other Code ... | |||
} | |||
<b><AndroidManifest.xml></b> | |||
<application | |||
android:name="<b>.MyCustomApplication</b>" | |||
android:allowBackup="true" | |||
android:label="@string/app_name" | |||
android:supportsRtl="true" | |||
android:theme="@style/AppTheme" > | |||
Other Code ... | |||
</application> | |||
<br> | |||
<br> | |||
[[IDGraph_Android_SDK_Developer_Guide|回IDGraph Android SDK首頁]] |
於 2017年11月10日 (五) 10:11 的修訂
在回報Log前,必須讓SDK進行初始化,您需要執行下列函式
IDGraphTracker.getInstance().init(Context, <PROFILE_ID>, isDebug);
- 第一個參數為Context
- 第二個參數請填入你的Profile ID (可向您的TAMedia窗口詢問)
- 第三個為boolean值,設為true時,每次回報會出現Toast訊息框以確認回報是否成功
若要進行回報,需呼叫下列函式
IDGraphTracker.getInstance().reportTrackLog();
上述提及的函式,可參考下列方式加入您的專案
- Without Application Class
- 若APP專案未擁有自己的Application class,則必須將追蹤碼放在自己的APP首頁,也就是第一個出現的Activity,透過此方式,每次APP重啟時都會觸發回報, 程式碼如下:
<MainActivity.java> public class MainActivity extends AppCompatActivity { private static final String PROFILE_ID = "<Your Profile ID>"; private static final boolean isDebug = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initial IDGraphTracker.getInstance().init(this, PROFILE_ID, isDebug); // Send Tracking Log IDGraphTracker.getInstance().reportTrackLog(); } Other Code ... }
- With Application Class
- 若APP專案有自己的Application class,可將追蹤碼放在此class,由於Application的執行時間是在Activity啟動前,因此會比Without Application Class更早回報,但是如果APP是透過Back鍵關掉的話,由於Application還會留在系統一小段時間, 導致使用者短時間內再次打開APP時並不會觸發回報, 必須等待系統將其回收或是使用者自行把APP刷掉(在桌面點選Menu Button, 再將APP上滑關閉), Application才算是真正結束
- 程式碼如下:
<MyCustomApplication.java> public class MyCustomApplication extends Application { private static final String PROFILE_ID = "<Your Profile ID>"; private static final boolean isDebug = false; // Called when the application is starting, before any other application objects have been created. // Overriding this method is totally optional! @Override public void onCreate() { super.onCreate(); // Initial IDGraphTracker.getInstance().init(this, PROFILE_ID, isDebug); // Send Tracking Log IDGraphTracker.getInstance().reportTrackLog(); } Other Code ... }
<AndroidManifest.xml> <application android:name=".MyCustomApplication" android:allowBackup="true" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme" > Other Code ... </application>