This guide will walk you through the complete installation process of the User Analytics SDK.
Before you begin, ensure you have:
Open your project’s settings.gradle
file and add JitPack repository:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' } // Add this line
}
}
If you’re using the older Gradle structure, add to your project-level build.gradle
:
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' } // Add this line
}
}
Open your app-level build.gradle
file (app/build.gradle
) and add:
dependencies {
// Other dependencies...
implementation 'com.github.nSella10:UserAnalyticsSDK:v1.0.6'
}
Add internet permission to your AndroidManifest.xml
:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Add this permission -->
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<!-- Your activities -->
</application>
</manifest>
For enhanced security, you can add network security configuration:
Create res/xml/network_security_config.xml
:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="false">
<domain includeSubdomains="true">d1xb34m3k0zeus.cloudfront.net</domain>
</domain-config>
</network-security-config>
Then reference it in your AndroidManifest.xml
:
<application
android:networkSecurityConfig="@xml/network_security_config"
... >
ak_xxxxxxxxxx
)Add initialization code to your main activity:
import com.analytics.analyticstracker.AnalyticsTracker;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize the SDK with your API key
AnalyticsTracker.init("https://d1xb34m3k0zeus.cloudfront.net/", "YOUR_API_KEY_HERE");
}
}
Run a clean build to ensure everything compiles:
./gradlew clean build
Add a simple test event:
// Test event
Map<String, Object> properties = new HashMap<>();
properties.put("test", "installation");
AnalyticsTracker.trackEvent("test_user", "sdk_installed", properties);
For production apps, consider storing your API key securely:
In your build.gradle
:
android {
defaultConfig {
buildConfigField "String", "ANALYTICS_API_KEY", "\"your_api_key_here\""
}
buildFeatures {
buildConfig true
}
}
Usage:
AnalyticsTracker.init("https://d1xb34m3k0zeus.cloudfront.net/", BuildConfig.ANALYTICS_API_KEY);
Create local.properties
(add to .gitignore
):
ANALYTICS_API_KEY=your_api_key_here
In build.gradle
:
def localProps = new Properties()
localProps.load(new FileInputStream(rootProject.file("local.properties")))
android {
defaultConfig {
buildConfigField "String", "ANALYTICS_API_KEY", "\"${localProps['ANALYTICS_API_KEY']}\""
}
}
Build Error: “Could not resolve dependency”
Build > Clean Project
Network Error: “Unable to connect”
API Key Error: “Invalid API Key”
ak_xxxxxxxxxx
If you encounter issues:
After successful installation:
Installation complete! 🎉 You’re ready to start tracking analytics.