Amplitude SDK Quickstart Guide
Use this guide to get started with the Amplitude SDKs. Choose your target platform:
The Browser SDK lets you send events to Amplitude. See the Browser SDK documentation for additional configurations and advanced topics.
Table of Contents
Initialize the library¶
First, install dependencies and initialize the library in your app.
Install the dependency¶
Install the dependency using NPM, YARN, or script loader.
This package is also distributed through a CDN. Copy and paste this script in your HTML file.
<script type="text/javascript">
!function(){"use strict";!function(e,t){var n=e.amplitude||{_q:[],_iq:{}};if(n.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var r=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},s=function(e,t,n){return function(r){e._q.push({name:t,args:Array.prototype.slice.call(n,0),resolve:r})}},o=function(e,t,n){e[t]=function(){if(n)return{promise:new Promise(s(e,t,Array.prototype.slice.call(arguments)))}}},i=function(e){for(var t=0;t<y.length;t++)o(e,y[t],!1);for(var n=0;n<g.length;n++)o(e,g[n],!0)};n.invoked=!0;var a=t.createElement("script");a.type="text/javascript",a.integrity="sha384-TPZhteUkZj8CAyBx+GZZytBdkuKnhKsSKcCoVCq0QSteWf/Kw5Kb9oVFUROLE1l3",a.crossOrigin="anonymous",a.async=!0,a.src="https://cdn.amplitude.com/libs/analytics-browser-1.9.1-min.js.gz",a.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var c=t.getElementsByTagName("script")[0];c.parentNode.insertBefore(a,c);for(var u=function(){return this._q=[],this},l=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],p=0;p<l.length;p++)r(u,l[p]);n.Identify=u;for(var d=function(){return this._q=[],this},f=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setEventProperties"],v=0;v<f.length;v++)r(d,f[v]);n.Revenue=d;var y=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset"],g=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];i(n),n.createInstance=function(e){return n._iq[e]={_q:[]},i(n._iq[e]),n._iq[e]},e.amplitude=n}}(window,document)}();
</script>
npm install @amplitude/analytics-browser
Import Amplitude to your project
import * as amplitude from '@amplitude/analytics-browser';
yarn add @amplitude/analytics-browser
Import Amplitude to your project
import * as amplitude from '@amplitude/analytics-browser';
Initialization¶
Before you can instrument, you must initialize the SDK using the API key for your Amplitude project.
amplitude.init(AMPLITUDE_API_KEY);
Send data¶
Next, send data from your app or website to Amplitude.
const eventProperties = {
buttonColor: 'primary',
};
amplitude.track('Button Clicked', eventProperties);
Check for success¶
After you begin sending data to Amplitude, use one of the debugging tools to check your instrumentation and validate your events.
Complete code example¶
Here's a complete example of how to use the SDK in your own app.
amplitude.init(AMPLITUDE_API_KEY, 'user@amplitude.com');
const eventProperties = {
buttonColor: 'primary',
};
const identifyObj = new Identify();
identifyObj.set('location', 'LAX');
amplitude.identify(identifyObj);
amplitude.track('Button Clicked', eventProperties);
Learn more available functionalities in Browser SDK.
Enforce event schemas (Ampli)¶
The Ampli CLI, Ampli Wrapper, and Amplitude SDK work together to generate a tracking library based on your Tracking Plan. The autogenerated library provides type-safety, supports linting, and enable features like input validation which contextualizes your analytics instrumentation, and reduces instrumentation mistakes in your production environments.
import { ampli } from './ampli';
ampli.load({ environment: 'production' });
ampli.buttonClicked({
buttonColor: 'primary',
});
Learn more about and set up the Browser Ampli.
The Node.js SDK lets you send events to Amplitude. See the Node.js SDK documentation for additional configurations and advanced topics.
Table of Contents
Initialize the library¶
First, install dependencies and initialize the library in your app.
Install the dependency¶
Install the dependency using NPM or YARN.
npm install @amplitude/analytics-node
yarn add @amplitude/analytics-node
Initialization¶
Before you can instrument, you must initialize the SDK using the API key for your Amplitude project.
import { init } from '@amplitude/analytics-node';
init(AMPLITUDE_API_KEY);
import { init } from '@amplitude/analytics-node';
init(AMPLITUDE_API_KEY);
Send data¶
Next, send data from your app or website to Amplitude.
import { track } from '@amplitude/analytics-node';
const eventProperties = {
buttonColor: 'primary',
};
track('Button Clicked', eventProperties, {
user_id: 'user@amplitude.com',
});
import { track } from '@amplitude/analytics-node';
const eventProperties = {
buttonColor: 'primary',
};
track('Button Clicked', eventProperties, {
user_id: 'user@amplitude.com',
});
Check for success¶
After you begin sending data to Amplitude, use one of the debugging tools to check your instrumentation and validate your events.
Complete code example¶
Here's a complete example of how to use the SDK in your own app.
import { init, identify, Identify, track } from '@amplitude/analytics-node';
init(AMPLITUDE_API_KEY);
const identifyObj = new Identify();
identify(identifyObj, {
user_id: 'user@amplitude.com',
});
const eventProperties = {
buttonColor: 'primary',
};
track('Button Clicked', eventProperties, {
user_id: 'user@amplitude.com',
});
import { init, identify, Identify, track } from '@amplitude/analytics-node';
init(AMPLITUDE_API_KEY);
const identifyObj = new Identify();
identify(identifyObj, {
user_id: 'user@amplitude.com',
});
const eventProperties = {
buttonColor: 'primary',
};
track('Button Clicked', eventProperties, {
user_id: 'user@amplitude.com',
});
Learn more available functionalities in Node.js SDK.
Enforce event schemas (Ampli)¶
The Ampli CLI, Ampli Wrapper, and Amplitude SDK work together to generate a tracking library based on your Tracking Plan. The autogenerated library provides type-safety, supports linting, and enable features like input validation which contextualizes your analytics instrumentation, and reduces instrumentation mistakes in your production environments.
ampli.load();
ampli.yourEventType('ampli-user-id', {
stringProp: 'Strongly typed property',
booleanProp: true,
});
ampli.load();
ampli.yourEventType('ampli-user-id', {
stringProp: 'Strongly typed property',
booleanProp: true,
});
Learn more about Node Ampli.
The Android SDK lets you send events to Amplitude. See the Android SDK documentation for additional configurations and advanced topics.
Get started fast with an example project (click to expand)
Kotlin Android example project (click to expand)
To get started fast, check out an example Kotlin Android project:
- Clone the repo.
- Open it with Android Studio.
- Change your API key in
build.gradle
forModule: samples: kotlin-android-app
under Gradle Scripts. - Sync the project with Gradle files.
- Run
samples.kotlin-android-app
. - Press the button to send events in the running application.
- Check for success.
Java Android example project (click to expand)
To get started fast, check out an example Java Android project:
- Clone the repo.
- Open it with Android Studio.
- Change your API key in
build.gradle
forModule: samples: java-android-app
under Gradle Scripts. - Sync the project with Gradle files.
- Run
samples.java-android-app
. - Press the button to send events in the running application.
- Check for success.
Kotlin JVM example project (click to expand)
To get started fast, check out an example Kotlin JVM project:
- Clone the repo.
- Open it with Android Studio.
- Change your API key in
samples/kotlin-jvm-app/main/java/main.kt
and run the file. - Check for success.
Quickstart table of contents
Skip to a section:
Initialize the library¶
First, install dependencies and initialize the library in your app.
Install the dependency¶
Amplitude recommends using Android Studio as an IDE and Gradle to manage dependencies.
If you are using Gradle in your project, include the following dependencies in build.gradle
file. And then sync project with Gradle files.
dependencies {
implementation 'com.amplitude:analytics-android:1.+'
}
If you are using Maven in your project, the jar is available on Maven Central using the following configuration in your pom.xml
<dependency>
<groupId>com.amplitude</groupId>
<artifactId>analytics-android</artifactId>
<version>[1.0,2.0)</version>
</dependency>
Add permissions¶
To report events to Amplitude, add the INTERNET permission to your AndroidManifest.xml
file.
<uses-permission android:name="android.permission.INTERNET" />
For Android 6.0 (Marshmallow) and above, explicitly add the READ_PHONE_STATE
permission to fetch phone carrier information. If you don't add this permission, the SDK still works, but doesn't track phone carrier information.
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
The SDK internally uses a few Java 8 language APIs through desugaring. Make sure your project either enables desugaring or requires a minimum API level of 16.
Initialization¶
Before you can instrument, you must initialize the SDK using the API key for your Amplitude project.
Amplitude recommends doing the initialization in the Main Activity, which never gets destroyed, or the Application class if you have one. After it's initialized, you can use the Android SDK anywhere in your Android application.
import com.amplitude.android.Amplitude
val amplitude = Amplitude(
Configuration(
apiKey = AMPLITUDE_API_KEY,
context = applicationContext
)
)
import com.amplitude.android.Amplitude;
Amplitude amplitude = new Amplitude(new Configuration(
apiKey = AMPLITUDE_API_KEY,
context = applicationContext
));
EU data residency¶
You can configure the server zone when initializing the client for sending data to Amplitude's EU servers. The SDK sends data based on the server zone if it's set.
Note
For EU data residency, the project must be set up inside Amplitude EU. You must initialize the SDK with the API key from Amplitude EU.
import com.amplitude.android.Amplitude
val amplitude = Amplitude(
Configuration(
apiKey = AMPLITUDE_API_KEY,
context = applicationContext,
serverZone = ServerZone.EU
)
)
import com.amplitude.android.Amplitude;
Amplitude amplitude = new Amplitude(new Configuration(
apiKey = AMPLITUDE_API_KEY,
context = applicationContext,
serverZone = ServerZone.EU
));
Send data¶
Next, send data from your app or website to Amplitude.
Events tracked are buffered locally and flushed every 30 seconds. After calling track() in your app, it may take several seconds for event data to appear in Amplitude.
// Track a basic event
amplitude.track("Button Clicked")
// Track events with optional properties
amplitude.track(
"Button Clicked",
mapOf("buttonColor" to "primary")
)
// Track a basic event
amplitude.track("Button Clicked");
// Track events with optional properties
amplitude.track("Button Clicked", new HashMap() {{
put("buttonColor", "primary");
}});
Check for success¶
After you begin sending data to Amplitude, use one of the debugging tools to check your instrumentation and validate your events.
Complete code example¶
Here's a complete example of how to use the SDK in your own app.
package com.amplitude.android.sample
import android.os.Bundle
import com.amplitude.core.events.Identify
import com.amplitude.android.Amplitude
import com.amplitude.android.Configuration
class MainActivity : AppCompatActivity() {
private val amplitude = Amplitude(
Configuration(
apiKey = AMPLITUDE_API_KEY,
context = applicationContext
)
);
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val identify = Identify()
identify.set("user-platform", "android")
amplitude.identify(identify)
amplitude.track("test event properties", mapOf("test" to "test event property value"))
}
}
package com.amplitude.android.sample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.amplitude.android.Amplitude;
import com.amplitude.core.events.Identify;
import java.util.HashMap;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Amplitude amplitude = new Amplitude(new Configuration(
apiKey = AMPLITUDE_API_KEY,
context = applicationContext
));
Identify identify = new Identify().set("user-platform", "android")
amplitude.identify(identify);
amplitude.track("test event properties", new HashMap() {{
put("test", "test event property value");
}});
}
}
Learn more available functionalities in Android SDK.
Enforce event schemas (Ampli)¶
The Ampli CLI, Ampli Wrapper, and Amplitude SDK work together to generate a tracking library based on your Tracking Plan. The autogenerated library provides type-safety, supports linting, and enable features like input validation which contextualizes your analytics instrumentation, and reduces instrumentation mistakes in your production environments.
ampli.load()
ampli.yourEventType(
stringProp = "Strongly typed property",
booleanProp = true
)
Ampli.getInstance().load();
Ampli.getInstance().yourEventType(
YourEventType.builder()
.stringProp("Strongly typed property")
.booleanProp(true)
.build()
);
Learn more about Ampli Android.
The iOS SDK lets you send events to Amplitude. See the iOS SDK documentation for additional configurations and advanced topics.
Warning
This is the time tested iOS SDK, however here is a new version in beta that is highly recommended for all customers using Swift. The latest iOS Swift SDK has additional features such as plugins and more. See the Migration Guide for more help.
Please note that the latest iOS Swift SDK is NOT compatible with Objective-C projects. Use this SDK if your project requires compatibility with Objective-C.
Table of Contents
Initialize the library¶
First, install dependencies and initialize the library in your app.
Install the dependency¶
Install the Amplitude Analytics iOS SDK via CocoaPods, Carthage, or Swift Package Manager.
Add the dependency to Podfile
.
pod 'Amplitude', '~> 8.14'
pod install
in the project directory to download the dependency.
- Navigate to
File
>Swift Package Manager
>Add Package Dependency
. - Enter
https://github.com/amplitude/Amplitude-iOS
into the search bar. - It automatically resolves to the latest version.
The Amplitude-iOS package appears as a dependency after it's added.
Add the following line to your Cartfile
.
github "amplitude/Amplitude-iOS" ~> 8.14
Initialization¶
Before you can instrument, you must initialize the SDK using the API key for your Amplitude project.
#import <Amplitude/Amplitude.h>
[[Amplitude instance] initializeApiKey:@"YOUR_API_KEY"];
import Amplitude
Amplitude.instance().initializeApiKey("YOUR_API_KEY")
EU data residency¶
You can configure the server zone when initializing the client for sending data to Amplitude's EU servers. The SDK sends data based on the server zone if it's set.
Note
For EU data residency, the project must be set up inside Amplitude EU. You must initialize the SDK with the API key from Amplitude EU.
Beginning with version 8.5.0
, you can configure the server zone after initializing the client for sending data to Amplitude's EU servers. The SDK sends data based on the server zone if it's set. The server zone configuration supports dynamic configuration as well.
For earlier versions, you need to configure the serverURL
property after initializing the client.
// For versions starting from 8.5.0
// No need to call setServerUrl for sending data to Amplitude's EU servers
[[Amplitude instance] setServerZone:AMPServerZone.EU];
// For earlier versions
[[Amplitude instance] setServerUrl: @"https://api.eu.amplitude.com"];
// For versions starting from 8.5.0
// No need to call setServerUrl for sending data to Amplitude's EU servers
Amplitude.instance().setServerZone(AMPServerZone.EU)
// For earlier versions
Amplitude.instance().setServerUrl("https://api.eu.amplitude.com")
Send data¶
Next, send data from your app or website to Amplitude.
[[Amplitude instance] logEvent:@"Button Clicked"];
Amplitude.instance().logEvent("Button Click")
Check for success¶
After you begin sending data to Amplitude, use one of the debugging tools to check your instrumentation and validate your events.
Complete code example¶
Here's a complete example of how to use the SDK in your own app.
#import "Amplitude.h"
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Enable sending automatic session events
[Amplitude instance].trackingSessionEvents = YES;
// Initialize SDK
[[Amplitude instance] initializeApiKey:@"YOUR_API_KEY"];
// Set userId
[[Amplitude instance] setUserId:@"userId"];
// Log an event
[[Amplitude instance] logEvent:@"app_start"];
}
import Amplitude
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Enable sending automatic session events
Amplitude.instance().trackingSessionEvents = true
// Initialize SDK
Amplitude.instance().initializeApiKey("YOUR_API_KEY")
// Set userId
Amplitude.instance().setUserId("userId")
// Log an event
Amplitude.instance().logEvent("app_start")
return true
}
Learn more available functionalities in iOS SDK.
Enforce event schemas (Ampli)¶
The Ampli CLI, Ampli Wrapper, and Amplitude SDK work together to generate a tracking library based on your Tracking Plan. The autogenerated library provides type-safety, supports linting, and enable features like input validation which contextualizes your analytics instrumentation, and reduces instrumentation mistakes in your production environments.
Ampli *ampli = [Ampli instance];
[ampli load];
[ampli yourEventType:[YourEventType stringProp:@[@"Strongly typed property"]
booleanProp:true]];
ampli.load();
ampli.yourEventType(
stringProp: "Strongly typed property",
booleanProp: true
)
Learn more about Ampli iOS.
The iOS SDK lets you send events to Amplitude. See the iOS SDK (Beta) documentation for additional configurations and advanced topics.
iOS Swift SDK (Beta)
This SDK is currently in beta version. It can only be used in Swift projects and is NOT compatible with Objective-C projects. If you require support for Objective-C or have any concern with the Beta version, check out the non-Beta iOS SDK.
To migrate to the latest version of Amplitude iOS SDK, see the Migration Guide.
Table of Contents
Initialize the library¶
First, install dependencies and initialize the library in your app.
Install the dependency¶
Install the Amplitude Analytics iOS SDK via CocoaPods, Carthage, or Swift Package Manager.
- Add dependency to
Podfile
.pod 'AmplitudeSwift', '~> 0.3.0'
- Run
pod install
in the project directory to install the dependency.
- Navigate to
File
>Swift Package Manager
> 'Add Package Dependency`. This opens a dialog that allows you to add a package dependency. - Enter the URL
https://github.com/amplitude/Amplitude-Swift
in the search bar. - Xcode will automatically resolve to the latest version. Or you can select a specific version.
- Click the "Next" button to confirm the addition of the package as a dependency.
- Build your project to make sure the package is properly integrated.
Add the following line to your Cartfile
.
github "amplitude/Amplitude-Swift" ~> 0.3.0
Initialization¶
Before you can instrument, you must initialize the SDK using the API key for your Amplitude project.
import Amplitude_Swift
let amplitude = Amplitude(
configuration: Configuration(
apiKey: "YOUR-API-KEY"
)
)
EU data residency¶
You can configure the server zone when initializing the client for sending data to Amplitude's EU servers. The SDK sends data based on the server zone if it's set.
Note
For EU data residency, the project must be set up inside Amplitude EU. You must initialize the SDK with the API key from Amplitude EU.
import Amplitude_Swift
let amplitude = Amplitude(
Configuration(
apiKey: "YOUR-API-KEY",
serverZone: ServerZone.EU
)
)
Send data¶
Next, send data from your app or website to Amplitude.
amplitude.track(
eventType: "Button Clicked",
eventProperties: ["my event prop key": "my event prop value"]
)
Check for success¶
After you begin sending data to Amplitude, use one of the debugging tools to check your instrumentation and validate your events.
Complete code example¶
Here's a complete example of how to use the SDK in your own app.
import Amplitude_Swift
let amplitude = Amplitude(
configuration: Configuration(
apiKey: "YOUR-API-KEY"
)
)
amplitude.track(
eventType: "Button Clicked",
eventProperties: ["my event prop key": "my event prop value"]
)
Learn more available functionalities in iOS SDK.
Enforce event schemas (Ampli)¶
The Ampli CLI, Ampli Wrapper, and Amplitude SDK work together to generate a tracking library based on your Tracking Plan. The autogenerated library provides type-safety, supports linting, and enable features like input validation which contextualizes your analytics instrumentation, and reduces instrumentation mistakes in your production environments.
Ampli Wrapper Not Yet Available
The Ampli Wrapper is an autogenerated library based on your pre-defined tracking plan. The Ampli Wrapper is not yet available for this SDK. To use Ampli see the non-Beta SDK and Ampli Wrapper instead.
Coming soon.
This is the documentation for the Amplitude Analytics Java SDK. This is not the Android SDK. See the Java SDK documentation for additional configurations and advanced topics.
Table of Contents
Initialize the library¶
First, install dependencies and initialize the library in your app.
Install the dependency¶
If you are using Gradle in your project, include the following dependencies in build.gradle
file. And then sync project with Gradle files.
dependencies {
implementation 'org.json:json:20201115'
implementation 'com.amplitude:java-sdk:1.+'
}
Download the latest JAR file and add it to the project's buildpath. See instructions for your IDE.
Initialization¶
Before you can instrument, you must initialize the SDK using the API key for your Amplitude project.
Import Amplitude into any file that uses it. Amplitude uses the open source JSONObject
library to conveniently create JSON key-value objects.
import com.amplitude.Amplitude;
import org.json.JSONObject;
Amplitude amplitude = Amplitude.getInstance();
amplitude.init(AMPLITUDE_API_KEY);
import com.amplitude.Amplitude
import org.json.JSONObject
val amplitude = Amplitude.getInstance()
amplitude.init(AMPLITUDE_API_KEY)
EU data residency¶
You can configure the server zone when initializing the client for sending data to Amplitude's EU servers. The SDK sends data based on the server zone if it's set.
Note
For EU data residency, the project must be set up inside Amplitude EU. You must initialize the SDK with the API key from Amplitude EU.
import com.amplitude.Amplitude;
import org.json.JSONObject;
Amplitude amplitude = Amplitude.getInstance();
amplitude.init(AMPLITUDE_API_KEY);
amplitude.setServerUrl("https://api.eu.amplitude.com/2/httpapi");
import com.amplitude.Amplitude
import org.json.JSONObject
val amplitude = Amplitude.getInstance()
amplitude.init(AMPLITUDE_API_KEY)
amplitude.setServerUrl("https://api.eu.amplitude.com/2/httpapi");
Send data¶
Next, send data from your app or website to Amplitude.
amplitude.logEvent(new Event("Button Clicked", "test_user_id"));
amplitude.logEvent(Event("Button Clicked", "test_user_id"))
Check for success¶
After you begin sending data to Amplitude, use one of the debugging tools to check your instrumentation and validate your events.
Complete code example¶
Here's a complete example of how to use the SDK in your own app.
import com.amplitude.Amplitude;
import org.json.JSONObject;
Amplitude amplitude = Amplitude.getInstance();
amplitude.init(AMPLITUDE_API_KEY);
Event event = new Event("Button Clicked", "test_user_id");
JSONObject eventProps = new JSONObject();
try {
eventProps.put("Hover Time", 10).put("prop_2", "value_2");
} catch (JSONException e) {
System.err.println("Invalid JSON");
e.printStackTrace();
}
event.eventProperties = eventProps;
amplitude.logEvent(event);
import com.amplitude.Amplitude
import org.json.JSONObject
val amplitude = Amplitude.getInstance()
amplitude.init(AMPLITUDE_API_KEY)
val eventProps= JSONObject()
eventProps.put("Hover Time", 10).put("prop_2", "value_2")
val event = Event("Button Clicked", "test_user_id")
event.eventProperties = eventProps
amplitude.logEvent(event)
Learn more in Java SDK.
Enforce event schemas (Ampli)¶
The Ampli CLI, Ampli Wrapper, and Amplitude SDK work together to generate a tracking library based on your Tracking Plan. The autogenerated library provides type-safety, supports linting, and enable features like input validation which contextualizes your analytics instrumentation, and reduces instrumentation mistakes in your production environments.
Ampli.getInstance().load();
Ampli.getInstance().yourEventType("ampli-user-id",
YourEventType.builder("Strongly typed property")
.stringProp()
.booleanProp(false)
.build()
);
Ampli.getInstance().load()
Ampli.getInstance().yourEventType("ampli-user-id",
YourEventType(
stringProp = "Strongly typed property",
booleanProp = false
)
)
Learn more about Ampli Java.
The Python SDK lets you send events to Amplitude. See the Pythohn SDK documentation for additional configurations and advanced topics.
Table of Contents
Initialize the library¶
First, install dependencies and initialize the library in your app.
Install the dependency¶
Install amplitude-analytics
using pip:
pip install amplitude-analytics
Initialization¶
Before you can instrument, you must initialize the SDK using the API key for your Amplitude project.
from amplitude import Amplitude
amplitude = Amplitude(AMPLITUDE_API_KEY)
EU data residency¶
You can configure the server zone when initializing the client for sending data to Amplitude's EU servers. The SDK sends data based on the server zone if it's set.
Note
For EU data residency, the project must be set up inside Amplitude EU. You must initialize the SDK with the API key from Amplitude EU.
from amplitude import Amplitude
amplitude = Amplitude(AMPLITUDE_API_KEY)
amplitude.configuration.server_zone = 'EU'
Send data¶
Next, send data from your app or website to Amplitude.
from amplitude import BaseEvent
amplitude.track(
BaseEvent(
event_type="type of event",
user_id="USER_ID",
device_id="DEVICE_ID",
event_properties={
"source": "notification"
}
)
)
Check for success¶
After you begin sending data to Amplitude, use one of the debugging tools to check your instrumentation and validate your events.
Complete code example¶
Here's a complete example of how to use the SDK in your own app.
from amplitude import Amplitude, Identify, BaseEvent
amplitude = Amplitude("AMPLITUDE_API_KEY")
identify_obj=Identify()
identify_obj.set("location", "LAX")
amplitude.identify(identify_obj)
amplitude.track(
BaseEvent(
event_type="type of event",
user_id="USER_ID",
device_id="DEVICE_ID",
event_properties={
"source": "notification"
}
)
)
# Flush the event buffer
amplitude.flush()
# Shutdown the client, recommend to call before program exit
amplitude.shutdown()
Learn more available functionalities in Python SDK.
Enforce event schemas (Ampli)¶
The Ampli CLI, Ampli Wrapper, and Amplitude SDK work together to generate a tracking library based on your Tracking Plan. The autogenerated library provides type-safety, supports linting, and enable features like input validation which contextualizes your analytics instrumentation, and reduces instrumentation mistakes in your production environments.
ampli.load()
ampli.yourEventType(
"user_id",
YourEventType(
stringProp= "Strongly typed property",
booleanProp=True
)
)
Learn more about Ampli Python.
The React Native SDK lets you send events to Amplitude. See the React Native SDK documentation for additional configurations and advanced topics.
Table of Contents
Initialize the library¶
First, install dependencies and initialize the library in your app.
Install the dependency¶
npm install @amplitude/analytics-react-native
npm install @react-native-async-storage/async-storage
yarn add @amplitude/analytics-react-native
yarn add @react-native-async-storage/async-storage
expo install @amplitude/analytics-react-native
expo install @react-native-async-storage/async-storage
Install the native modules to run the SDK on iOS.
cd ios
pod install
Initialization¶
Before you can instrument, you must initialize the SDK using the API key for your Amplitude project.
import { init } from '@amplitude/analytics-react-native';
init(AMPLITUDE_API_KEY, 'user@amplitude.com');
import { init } from '@amplitude/analytics-react-native';
init(AMPLITUDE_API_KEY, 'user@amplitude.com');
Send data¶
Next, send data from your app or website to Amplitude.
import { track } from '@amplitude/analytics-react-native';
const eventProperties = {
buttonColor: 'primary',
};
track('Button Clicked', eventProperties);
import { track } from '@amplitude/analytics-react-native';
const eventProperties = {
buttonColor: 'primary',
};
track('Button Clicked', eventProperties);
Check for success¶
After you begin sending data to Amplitude, use one of the debugging tools to check your instrumentation and validate your events.
Complete code example¶
Here's a complete example of how to use the SDK in your own app.
import { init, track, Identify, identify } from '@amplitude/analytics-react-native';
init(AMPLITUDE_API_KEY, 'user@amplitude.com');
const identifyObj = new Identify();
identifyObj.set('location', 'LAX');
identify(identifyObj);
const eventProperties = {
buttonColor: 'primary',
};
track('Button Clicked', eventProperties);
import { init, track, Identify, identify } from '@amplitude/analytics-react-native';
init(AMPLITUDE_API_KEY, 'user@amplitude.com');
const identifyObj = new Identify();
identifyObj.set('location', 'LAX');
identify(identifyObj);
const eventProperties = {
buttonColor: 'primary',
};
track('Button Clicked', eventProperties);
Learn more available functionalities in React Native SDK.
Enforce event schemas (Ampli)¶
The Ampli CLI, Ampli Wrapper, and Amplitude SDK work together to generate a tracking library based on your Tracking Plan. The autogenerated library provides type-safety, supports linting, and enable features like input validation which contextualizes your analytics instrumentation, and reduces instrumentation mistakes in your production environments.
ampli.load();
ampli.yourEventType({
stringProp: 'Strongly typed property',
});
ampli.load();
ampli.yourEventType({
stringProp: 'Strongly typed property',
});
Learn more about Ampli React Native.
The Flutter SDK lets you send events to Amplitude. See the Flutter SDK documentation for additional configurations and advanced topics.
Table of Contents
Initialize the library¶
First, install dependencies and initialize the library in your app.
Install the dependency¶
dependencies:
amplitude_flutter: ^3.13.0
iOS installation also need to add platform :ios, '10.0'
to your Podfile.
Learn more about adding the dependency.
Initialization¶
Before you can instrument, you must initialize the SDK using the API key for your Amplitude project.
import 'package:amplitude_flutter/amplitude.dart';
final Amplitude amplitude = Amplitude.getInstance();
amplitude.init(AMPLITUDE_API_KEY);
Send data¶
Next, send data from your app or website to Amplitude.
amplitude.logEvent('BUTTON_CLICKED', {"Hover Time": "100ms"});
Check for success¶
After you begin sending data to Amplitude, use one of the debugging tools to check your instrumentation and validate your events.
Complete code example¶
Here's a complete example of how to use the SDK in your own app.
import 'package:amplitude_flutter/amplitude.dart';
import 'package:amplitude_flutter/identify.dart';
class YourClass {
Future<void> exampleForAmplitude() async {
final Amplitude amplitude = Amplitude.getInstance();
amplitude.init(AMPLITUDE_API_KEY);
final Identify identify1 = Identify();
identify1.setOnce('sign_up_date', '2015-08-24');
Amplitude.getInstance().identify(identify1);
amplitude.logEvent('MyApp startup', eventProperties: {
'friend_num': 10,
'is_heavy_user': true
});
}
Learn more in Flutter SDK.
Enforce event schemas (Ampli)¶
The Ampli CLI, Ampli Wrapper, and Amplitude SDK work together to generate a tracking library based on your Tracking Plan. The autogenerated library provides type-safety, supports linting, and enable features like input validation which contextualizes your analytics instrumentation, and reduces instrumentation mistakes in your production environments.
More information TBD.
The Go SDK lets you send events to Amplitude. See the Go SDK documentation for additional configurations and advanced topics.
Table of Contents
Initialize the library¶
First, install dependencies and initialize the library in your app.
Install the dependency¶
go get github.com/amplitude/analytics-go
Initialization¶
Before you can instrument, you must initialize the SDK using the API key for your Amplitude project.
import (
"github.com/amplitude/analytics-go/amplitude"
)
config := amplitude.NewConfig(AMPLITUDE_API_KEY)
client := amplitude.NewClient(config)
Send data¶
Next, send data from your app or website to Amplitude.
client.Track(amplitude.Event{
EventType: "Button Clicked",
EventOptions: amplitude.EventOptions{
UserID: "user-id",
DeviceID: "device-id",
},
EventProperties: map[string]interface{}{"source": "notification"},
})
Check for success¶
After you begin sending data to Amplitude, use one of the debugging tools to check your instrumentation and validate your events.
Complete code example¶
Here's a complete example of how to use the SDK in your own app.
package main
import (
"github.com/amplitude/analytics-go/amplitude"
)
func main() {
config := amplitude.NewConfig(AMPLITUDE_API_KEY)
client := amplitude.NewClient(config)
identifyObj := amplitude.Identify{}
identifyObj.Set("location", "LAX")
client.Identify(identifyObj, amplitude.EventOptions{UserID: "user-id"})
client.Track(amplitude.Event{
EventType: "Button Clicked",
EventOptions: amplitude.EventOptions{
UserID: "user-id",
DeviceID: "device-id",
},
EventProperties: map[string]interface{}{"source": "notification"},
})
}
Learn more available functionalities in Go SDK.
Enforce event schemas (Ampli)¶
The Ampli CLI, Ampli Wrapper, and Amplitude SDK work together to generate a tracking library based on your Tracking Plan. The autogenerated library provides type-safety, supports linting, and enable features like input validation which contextualizes your analytics instrumentation, and reduces instrumentation mistakes in your production environments.
Coming soon.
The Amplitude Analytics Unity SDK is a plugin to simplify the integration of Amplitude iOS and Android SDKs into your Unity project. This SDK works with Unity 2019.3.11 and higher. See the Unity SDK documentation for additional configurations and advanced topics.
Table of Contents
Initialize the library¶
First, install dependencies and initialize the library in your app.
Install the dependency¶
Add 'https://github.com/amplitude/unity-plugin.git?path=/Assets'.
Download amplitude-unity.unitypackage
Learn more about the Unity package download.
Initialization¶
Before you can instrument, you must initialize the SDK using the API key for your Amplitude project.
Amplitude amplitude = Amplitude.getInstance()
amplitude.init("YOUR_API_KEY");
Send data¶
Next, send data from your app or website to Amplitude.
import 'package:amplitude_flutter/amplitude.dart';
amplitude.logEvent('MyApp startup', eventProperties: {
'friend_num': 10,
'is_heavy_user': true
});
Check for success¶
After you begin sending data to Amplitude, use one of the debugging tools to check your instrumentation and validate your events.
Complete code example¶
Here's a complete example of how to use the SDK in your own app.
Amplitude amplitude = Amplitude.getInstance();
amplitude.init("AMPLITUDE_API_KEY");
amplitude.addUserProperty("oranges", 5);
Dictionary<string, object> values = new Dictionary<string, object>();
values.Add("Key A", "Value A");
amplitude.addUserPropertyDict("user_facts", values);
JSONObjecteventProperties=newJSONObject().put("key", "value");
Amplitude.getInstance().logEvent("initialize_game", eventProperties);
Learn more in Unity SDK.
Enforce event schemas (Ampli)¶
The Ampli CLI, Ampli Wrapper, and Amplitude SDK work together to generate a tracking library based on your Tracking Plan. The autogenerated library provides type-safety, supports linting, and enable features like input validation which contextualizes your analytics instrumentation, and reduces instrumentation mistakes in your production environments.
More information TBD.
The Amplitude Analytics Unreal Engine SDK supports projects targeting iOS, MacOS, or tvOS. See the Unreal Engine SDK documentation for additional configurations and advanced topics.
Table of Contents
Initialize the library¶
First, install dependencies and initialize the library in your app.
Install the dependency¶
Download SDK and add to project¶
- Download
AmplitudeUnreal.zip.
- Unzip it into a folder inside your Unreal project's Plugins directory.
Download the latest AmplitudeUnreal.zip.
Initialization¶
Before you can instrument, you must initialize the SDK using the API key for your Amplitude project.
Enable the SDK plugin¶
Settings > Plugins > Project > Analytics
Learn more about how to enable SDK plugin.
Set Amplitude as your analytics provider¶
Settings -> Project Settings -> Analytics -> Providers
Learn more about how to set analytics provider.
Add your API keys¶
Settings -> Project Settings -> Analytics -> Amplitude
Learn more about how to set API keys.
#include "Runtime/Analytics/Analytics/Public/Analytics.h"
#include "Runtime/Analytics/Analytics/Public/Interfaces/IAnalyticsProvider.h"
Send data¶
Next, send data from your app or website to Amplitude.
TArray<FAnalyticsEventAttribute> AppendedAttributes;
AppendedAttributes.Emplace(TEXT("Test Event Prop key1"), TEXT("Test Event value1"));
AppendedAttributes.Emplace(TEXT("Test Event Prop key2"), TEXT("Test Event value2"));
FAnalytics::Get().GetDefaultConfiguredProvider()->RecordEvent(TEXT("Game Started"), AppendedAttributes);
Check for success¶
After you begin sending data to Amplitude, use one of the debugging tools to check your instrumentation and validate your events.
Complete code example¶
Here's a complete example of how to use the SDK in your own app.
FAnalytics::Get().GetDefaultConfiguredProvider()->SetLocation(TEXT("Test location"));
FAnalytics::Get().GetDefaultConfiguredProvider()->SetGender(TEXT("Test gender"));
FAnalytics::Get().GetDefaultConfiguredProvider()->SetAge(TEXT(27));
TArray<FAnalyticsEventAttribute> AppendedAttributes;
AppendedAttributes.Emplace(TEXT("Test Event Prop key1"), TEXT("Test Event value1"));
AppendedAttributes.Emplace(TEXT("Test Event Prop key2"), TEXT("Test Event value2"));
FAnalytics::Get().GetDefaultConfiguredProvider()->RecordEvent(TEXT("Game Started"), AppendedAttributes);
Learn more in Unreal SDK.
Enforce event schemas (Ampli)¶
The Ampli CLI, Ampli Wrapper, and Amplitude SDK work together to generate a tracking library based on your Tracking Plan. The autogenerated library provides type-safety, supports linting, and enable features like input validation which contextualizes your analytics instrumentation, and reduces instrumentation mistakes in your production environments.
More information TBD.