Skip to content

Commit

Permalink
Release v2.0.2 (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
hporter authored Dec 5, 2022
1 parent 56b3f1f commit 70b1a02
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 70 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Installation of the QubitSDK, to provide event tracking and lookup. To make use

| VERSION | UPDATES |
|---|---|
| 2.0.2 | Added ability to set custom device identifier.
| 2.0.1 | Resolve caching issue when campaigns are paused.
| 2.0.0 | Major release, bringing support for Placement API. Upgrade to 2.* to use this feature.
| 1.4.1 | Handle potential regression where /experiences endpoint does not return expected payload.
Expand All @@ -20,7 +21,7 @@ In `build.gradle` of your Android application module (usually *$projectRoot/app/

```
dependencies {
compile 'com.qubit:qubit-sdk-android:2.0.1'
compile 'com.qubit:qubit-sdk-android:2.0.2'
}
```

Expand Down Expand Up @@ -51,6 +52,10 @@ Qubit's Android SDK needs the following permissions to communicate with the serv

Note that you don't have to add these permissions to manifest of your application.

## Custom device identifier

By default Qubit SDK uses system `Settings.Secure.ANDROID_ID` value as a device identifier. However it is possible to use custom value instead by calling `QubitSDK.restartWithCustomDeviceId("my-custom-device-id")`. Calling `restartWithCustomDeviceId(null)` restores default behaviour. Changing device identifier once SDK is already started restarts SDK causing clearing all the caches and resending startup events.

# Send events

## Sending events
Expand Down
2 changes: 1 addition & 1 deletion qubit-sdk/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

version = '2.0.1'
version = '2.0.2'

ext.retrofit_version = '2.4.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface SdkConsumer {
}

private final SdkConsumer sdkConsumer;
private String deviceId;
private Context appContext;
private String trackingId;
private QBLogLevel logLevel;
Expand All @@ -25,6 +26,11 @@ interface SdkConsumer {
this.sdkConsumer = sdkConsumer;
}

public InitializationBuilder withCustomDeviceId(String deviceId) {
this.deviceId = deviceId;
return this;
}

/**
* Set context of Android application. It can be {@link Application} itself
* or result of {@link Context#getApplicationContext()}.
Expand Down Expand Up @@ -74,7 +80,7 @@ public void start() {
QBLogger.logLevel = logLevel;
}

SDK sdk = new SDK(appContext, trackingId);
SDK sdk = new SDK(appContext, trackingId, deviceId);
timings.addSplit("creation");
sdk.start();
timings.addSplit("starting");
Expand Down
17 changes: 17 additions & 0 deletions qubit-sdk/src/main/java/com/qubit/android/sdk/api/QubitSDK.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.qubit.android.sdk.api;

import android.content.Context;

import com.google.gson.JsonObject;
import com.qubit.android.sdk.api.placement.Placement;
import com.qubit.android.sdk.api.placement.PlacementMode;
Expand Down Expand Up @@ -67,6 +69,21 @@ public static String getDeviceId() {
return sdkSingleton.getDeviceId();
}

public static void restartWithCustomDeviceId(@Nullable String deviceId) {
if (sdkSingleton != null) {
// SDK is already initialized so it has to be restarted with a new deviceId
Context appContext = sdkSingleton.getAppContext();
String trackingId = sdkSingleton.getTrackingId();

release();
initialization()
.withCustomDeviceId(deviceId)
.inAppContext(appContext)
.withTrackingId(trackingId)
.start();
}
}

public static String getTrackingId() {
checkSdkInitialized();
return sdkSingleton.getTrackingId();
Expand Down
13 changes: 10 additions & 3 deletions qubit-sdk/src/main/java/com/qubit/android/sdk/internal/SDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@
import com.qubit.android.sdk.internal.session.repository.SessionRepository;
import com.qubit.android.sdk.internal.session.repository.SessionRepositoryImpl;

import org.jetbrains.annotations.Nullable;

import java.util.concurrent.Future;

public class SDK {

private final Context appContext;
private final NetworkStateServiceImpl networkStateService;
private final ConfigurationServiceImpl configurationService;
private final LookupServiceImpl lookupService;
Expand All @@ -66,7 +69,8 @@ public class SDK {
private final ExperienceInteractor experienceInteractor;
private final PlacementInteractor placementInteractor;

public SDK(Context appContext, String trackingId) {
public SDK(Context appContext, String trackingId, @Nullable String customDeviceId) {
this.appContext = appContext;
this.networkStateService = new NetworkStateServiceImpl(appContext);

ConfigurationRepository configurationRepository = new ConfigurationRepositoryImpl(appContext);
Expand All @@ -75,8 +79,7 @@ public SDK(Context appContext, String trackingId) {
new ConfigurationServiceImpl(networkStateService, configurationRepository, configurationConnectorBuilder);

this.trackingId = trackingId;
this.deviceId = new SecureAndroidIdDeviceIdProvider(appContext).getDeviceId();

this.deviceId = (customDeviceId == null) ? new SecureAndroidIdDeviceIdProvider(appContext).getDeviceId() : customDeviceId;

LookupRepository lookupRepository = new LookupRepositoryImpl(appContext);
LookupConnectorBuilder lookupConnectorBuilder = new LookupConnectorBuilderImpl(trackingId, deviceId);
Expand Down Expand Up @@ -154,6 +157,10 @@ public void stop() {
networkStateService.stop();
}

public Context getAppContext() {
return appContext;
}

public EventTrackerImpl getEventTracker() {
return eventTracker;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.qubit.android.sdk.internal.eventtracker;

import android.os.Build;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
Expand All @@ -23,7 +25,7 @@ class EventRestModelCreator {
private final String trackingId;
private final String deviceId;
private final int sample;
private final String source = "Android@" + BuildConfig.VERSION_NAME;
private final String source = "Android@OS:" + Build.VERSION.SDK_INT + "@SDK:" + BuildConfig.VERSION_NAME;

EventRestModelCreator(String trackingId, String deviceId) {
this.trackingId = trackingId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ class MainActivity : AppCompatActivity() {
findViewById<View>(R.id.placement_clickthrough).setOnClickListener {
placement?.clickthrough() ?: Toast.makeText(this, "No placement loaded", Toast.LENGTH_LONG).show()
}

findViewById<View>(R.id.device_id_custom).setOnClickListener {
QubitSDK.restartWithCustomDeviceId("custom")
}

findViewById<View>(R.id.device_id_reset).setOnClickListener {
QubitSDK.restartWithCustomDeviceId(null)
}
}

private fun getExperienceWithIds(list: List<Int>) {
Expand Down
142 changes: 79 additions & 63 deletions test-app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,76 +7,92 @@
android:padding="16dp"
tools:context="com.qubit.android.sdk.testapp.MainActivity">

<Button
android:id="@+id/send_view_event_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/send_view_event"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/send_view_event_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/send_view_event"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/send_interaction_event_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_button_margin_top"
android:text="@string/send_interaction_event"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/send_view_event_button" />
<Button
android:id="@+id/send_interaction_event_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_button_margin_top"
android:text="@string/send_interaction_event"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/send_view_event_button" />

<Button
android:id="@+id/send_20_events_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_button_margin_top"
android:text="@string/send_20_events"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/send_interaction_event_button" />
<Button
android:id="@+id/send_20_events_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_button_margin_top"
android:text="@string/send_20_events"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/send_interaction_event_button" />

<Button
android:id="@+id/get_experience"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_button_margin_top"
android:text="@string/get_experience_with_id_139731"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/send_20_events_button" />
<Button
android:id="@+id/get_experience"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_button_margin_top"
android:text="@string/get_experience_with_id_139731"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/send_20_events_button" />

<Button
android:id="@+id/get_experience_default"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_button_margin_top"
android:text="@string/get_all_experiences"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/get_experience" />
<Button
android:id="@+id/get_experience_default"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_button_margin_top"
android:text="@string/get_all_experiences"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/get_experience" />

<Button
android:id="@+id/get_example_placement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_button_margin_top"
android:text="@string/get_example_placement"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/get_experience_default" />
<Button
android:id="@+id/get_example_placement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_button_margin_top"
android:text="@string/get_example_placement"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/get_experience_default" />

<Button
android:id="@+id/placement_impression"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:text="@string/placement_impression"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/get_example_placement" />
<Button
android:id="@+id/placement_impression"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:text="@string/placement_impression"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/get_example_placement" />

<Button
android:id="@+id/placement_clickthrough"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:text="@string/placement_clickthrough"
app:layout_constraintStart_toEndOf="@+id/placement_impression"
app:layout_constraintTop_toBottomOf="@+id/get_example_placement" />
<Button
android:id="@+id/placement_clickthrough"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:text="@string/placement_clickthrough"
app:layout_constraintStart_toEndOf="@+id/placement_impression"
app:layout_constraintTop_toBottomOf="@+id/get_example_placement" />

<Button
android:id="@+id/device_id_custom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_button_margin_top"
android:text="@string/set_custom_device_id"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/placement_clickthrough" />

<Button
android:id="@+id/device_id_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/reset_custom_device_id"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/device_id_custom" />

</android.support.constraint.ConstraintLayout>
2 changes: 2 additions & 0 deletions test-app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
<string name="get_example_placement">Get example placement</string>
<string name="placement_impression">Impression</string>
<string name="placement_clickthrough">Clickthrough</string>
<string name="set_custom_device_id">Set custom deviceId</string>
<string name="reset_custom_device_id">Reset custom deviceId</string>
</resources>

0 comments on commit 70b1a02

Please sign in to comment.