The latest Android SDK version is 2.6.6
This is is a tutorial on how to implement Blue Triangle's Analytics SDK for android on a new or existing app. In this tutorial, we cover how to set up tracker with your site prefix and how to set timers for fragments, actions, and asynchronous functions. We also mention how to set up page names and traffic segments for various timers.
Note: This video may have references to old links and versions, for the most up to date details, please use the links and version numbers below. The most recent version is currently 2.6.6.
Usage:
Step 1 – add our repo to your module Gradle file
allprojects {
repositories {
google()
jcenter()
maven {
url "https://bluetriangletech.jfrog.io/artifactory/android-sdk-local/"
}
}
}
Step 2 – add the Blue Triangle analytics library as a dependency in your application Gradle file
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment:2.3.3'
implementation 'androidx.navigation:navigation-ui:2.3.3'
implementation 'bluetriangle.sdk.package:analytics:2.6.6'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
Step 3 – sync your Gradle dependencies
Step 4 – import the Blue Triangle tracker in your app delegate
import com.bluetriangle.analytics.Tracker;
public class MainActivity extends AppCompatActivity {
private Tracker tracker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tracker = Tracker.init(getApplicationContext(), "YOUR-SITE-PREFIX-HERE");
Step 5 – Change the site prefix of tracker to your own site prefix
tracker = Tracker.init(getApplicationContext(), "YOUR-SITE-PREFIX-HERE");
Step 6 – Turn on crash detection (optional)
In your app delegate where you set up tracker call track crashes
tracker = Tracker.init(getApplicationContext(), " YOUR-SITE-PREFIX-HERE ");
tracker.trackCrashes();
Step 7 – set up timers
import com.bluetriangle.analytics.Timer;
final Timer timer = new Timer("YOUR-PAGE-NAME", "YOUR-TRAFFIC-SEGMENT").start();
Step 8 – set up Custom Variables
import com.bluetriangle.analytics.Timer;
final Timer timer = new Timer("YOUR-PAGE-NAME", "YOUR-TRAFFIC-SEGMENT").start();
timer.setField("CV1","Custom Variable Data");
CV1 - CV5 Maps to Custom Variable 1 - 5 in the portal
CV6 - CV10 Maps to Custom Category 1 – 5 in the portal
CV11 - CV15 Maps to Variable 6-10 in the Portal
CN1 - CN20 is Custom Numeric 1 - 20
Step 9 – submit timer
timer.end().submit();
Full example of timer set up
import com.bluetriangle.analytics.Tracker;
import com.bluetriangle.analytics.Timer;
public class MainActivity extends AppCompatActivity {
private Tracker tracker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tracker = Tracker.init(getApplicationContext(), "YOUR-SITE-PREFIX-HERE");
tracker.trackCrashes();
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
final Timer timer = new Timer("Page 1", "Prod").start();
timer.setField("CV1","Custom Variable Data");
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
//wait(1000); //uncomment this to try out crash reporting
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
timer.end().submit();
}
});
}
Comments
0 comments
Please sign in to leave a comment.