SDK Quickstart

Browser

The Browser SDK sends events to Amplitude. For more information, see the Browser SDK 2 documentation for more configuration options and advanced topics.

Install the dependency

This package is also distributed through a CDN. Copy and paste this script in your HTML file. For the latest script loader, visit Amplitude's GitHub repository.

1npm install @amplitude/analytics-browser

Import Amplitude into your project:

1import * as amplitude from '@amplitude/analytics-browser';
1yarn add @amplitude/analytics-browser

Import Amplitude into your project:

1import * as amplitude from '@amplitude/analytics-browser';

Install the dependency using NPM, YARN, or script loader.

Initialize the SDK

Before you instrument,initialize the SDK using the API Key for your Amplitude project.

1amplitude.init(AMPLITUDE_API_KEY);

Send data

Next, send data from your app or website to Amplitude.

1const eventProperties = {
2 buttonColor: 'primary',
3};
4amplitude.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.

1amplitude.init(AMPLITUDE_API_KEY, 'user@amplitude.com');
2const eventProperties = {
3 buttonColor: 'primary',
4};
5 
6const identifyObj = new Identify();
7identifyObj.set('location', 'LAX');
8amplitude.identify(identifyObj);
9 
10amplitude.track('Button Clicked', eventProperties);

For more information, see Browser SDK 2.

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.

For more information, see Ampli for Browser SDK 2.0 or examples on GitHub for:

1import { ampli } from './ampli';
2ampli.load({ client: { apiKey: AMPLITUDE_API_KEY } });
3 
4ampli.buttonClicked({
5 buttonColor: 'primary',
6});

Node

The Node SDK sends events to Amplitude. For more information, see the Node SDK documentation for more configuration options and advanced topics.

Install the dependency

1npm install @amplitude/analytics-node
1yarn add @amplitude/analytics-node

Install the dependency with npm or yarn.

Initialize the SDK

Before you instrument,initialize the SDK using the API Key for your Amplitude project.

1import { init } from '@amplitude/analytics-node';
2 
3init(AMPLITUDE_API_KEY);
1import { init } from '@amplitude/analytics-node';
2 
3init(AMPLITUDE_API_KEY);

Send data

Next, send data from your app or website to Amplitude.

1import { track } from '@amplitude/analytics-node';
2 
3const eventProperties = {
4 buttonColor: 'primary',
5};
6 
7track('Button Clicked', eventProperties, {
8 user_id: 'user@amplitude.com',
9});
1import { track } from '@amplitude/analytics-node';
2 
3const eventProperties = {
4 buttonColor: 'primary',
5};
6 
7track('Button Clicked', eventProperties, {
8 user_id: 'user@amplitude.com',
9});

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.

1import { init, identify, Identify, track } from '@amplitude/analytics-node';
2init(AMPLITUDE_API_KEY);
3 
4const identifyObj = new Identify();
5identify(identifyObj, {
6 user_id: 'user@amplitude.com',
7});
8 
9const eventProperties = {
10 buttonColor: 'primary',
11};
12track('Button Clicked', eventProperties, {
13 user_id: 'user@amplitude.com',
14});
1import { init, identify, Identify, track } from '@amplitude/analytics-node';
2init(AMPLITUDE_API_KEY);
3 
4const identifyObj = new Identify();
5identify(identifyObj, {
6 user_id: 'user@amplitude.com',
7});
8 
9const eventProperties = {
10 buttonColor: 'primary',
11};
12track('Button Clicked', eventProperties, {
13 user_id: 'user@amplitude.com',
14});

For more information, see Node 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.

For more information, see Ampli for Node SDK or examples on GitHub for:

1ampli.load();
2 
3ampli.yourEventType('ampli-user-id', {
4 stringProp: 'Strongly typed property',
5 booleanProp: true,
6});
1ampli.load();
2 
3ampli.yourEventType('ampli-user-id', {
4 stringProp: 'Strongly typed property',
5 booleanProp: true,
6});

Android

The Android SDK sends events to Amplitude. For more information, see the Android-Kotlin SDK documentation for more configuration options and advanced topics.

Get started with an example project

Kotlin Android example project

To get started fast, check out an example Kotlin Android project:

  1. Clone the repo.
  2. Open it with Android Studio.
  3. Change your API key in build.gradle for Module: samples: kotlin-android-app under Gradle Scripts.
  4. Sync the project with Gradle files.
  5. Run samples.kotlin-android-app.
  6. Press the button to send events in the running application.

Java Android example project

To get started fast, check out an example Java Android project:

  1. Clone the repo.
  2. Open it with Android Studio.
  3. Change your API key in build.gradle for Module: samples: java-android-app under Gradle Scripts.
  4. Sync the project with Gradle files.
  5. Run samples.java-android-app.
  6. Press the button to send events in the running application.

Kotlin JVM example project

To get started fast, check out an example Kotlin JVM project:

  1. Clone the repo.
  2. Open it with Android Studio.
  3. Change your API key in samples/kotlin-jvm-app/main/java/main.kt and run the file.

Install the dependency

1dependencies {
2 implementation 'com.amplitude:analytics-android:1.+'
3}
1<dependency>
2 <groupId>com.amplitude</groupId>
3 <artifactId>analytics-android</artifactId>
4 <version>[1.0,2.0)</version>
5</dependency>

Add permissions

After you install the library, add the following to AndroidManifest.xml

1<uses-permission android:name="android.permission.INTERNET" />

For Android 6.0 (Marshmallow) and higher, explicitly add permission to fetch the device advertising ID.

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.

Initialize the SDK

Before you instrument,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.

Note

For EU data residency, the project must be set up inside Amplitude EU. Initialize the SDK with the API key from Amplitude EU.

1import com.amplitude.android.Amplitude
2 
3val amplitude = Amplitude(
4 Configuration(
5 apiKey = AMPLITUDE_API_KEY,
6 context = applicationContext
7 )
8)

Configure the serverZone property to configure your application to use European data residency.

1import com.amplitude.android.Amplitude
2 
3val amplitude = Amplitude(
4 Configuration(
5 apiKey = AMPLITUDE_API_KEY,
6 context = applicationContext,
7 serverZone = ServerZone.EU
8 )
9)
1import com.amplitude.android.Amplitude;
2 
3Amplitude amplitude = new Amplitude(new Configuration(
4 apiKey = AMPLITUDE_API_KEY,
5 context = applicationContext
6));

Configure the serverZone property to configure your application to use European data residency.

1import com.amplitude.android.Amplitude;
2 
3Amplitude amplitude = new Amplitude(new Configuration(
4 apiKey = AMPLITUDE_API_KEY,
5 context = applicationContext,
6 serverZone = ServerZone.EU
7));

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.

1// Track a basic event
2amplitude.track("Button Clicked")
3// Track events with optional properties
4amplitude.track(
5 "Button Clicked",
6 mapOf("buttonColor" to "primary")
7)
1// Track a basic event
2amplitude.track("Button Clicked");
3// Track events with optional properties
4amplitude.track("Button Clicked", new HashMap() {{
5 put("buttonColor", "primary");
6}});

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.

1package com.amplitude.android.sample
2 
3import android.os.Bundle
4import com.amplitude.core.events.Identify
5import com.amplitude.android.Amplitude
6import com.amplitude.android.Configuration
7 
8class MainActivity : AppCompatActivity() {
9 private val amplitude = Amplitude(
10 Configuration(
11 apiKey = AMPLITUDE_API_KEY,
12 context = applicationContext
13 )
14 );
15 
16 override fun onCreate(savedInstanceState: Bundle?) {
17 super.onCreate(savedInstanceState)
18 setContentView(R.layout.activity_main)
19 
20 val identify = Identify()
21 identify.set("user-platform", "android")
22 amplitude.identify(identify)
23 
24 amplitude.track("test event properties", mapOf("test" to "test event property value"))
25 }
26}
1package com.amplitude.android.sample;
2 
3import androidx.appcompat.app.AppCompatActivity;
4import android.os.Bundle;
5import com.amplitude.android.Amplitude;
6import com.amplitude.core.events.Identify;
7import java.util.HashMap;
8 
9public class MainActivity extends AppCompatActivity {
10 
11 @Override
12 protected void onCreate(Bundle savedInstanceState) {
13 super.onCreate(savedInstanceState);
14 setContentView(R.layout.activity_main);
15 Amplitude amplitude = new Amplitude(new Configuration(
16 apiKey = AMPLITUDE_API_KEY,
17 context = applicationContext
18 ));
19 
20 Identify identify = new Identify().set("user-platform", "android")
21 amplitude.identify(identify);
22 
23 amplitude.track("test event properties", new HashMap() {{
24 put("test", "test event property value");
25 }});
26 }
27}

For more information, see Android-Kotlin 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.

For more information, see Ampli for Android-Kotlin SDK or examples on GitHub for:

1ampli.load()
2 
3ampli.yourEventType(
4 stringProp = "Strongly typed property",
5 booleanProp = true
6)
1Ampli.getInstance().load();
2 
3Ampli.getInstance().yourEventType(
4 YourEventType.builder()
5 .stringProp("Strongly typed property")
6 .booleanProp(true)
7 .build()
8);

iOS

The iOS SDK sends events to Amplitude. For more information, see the iOS Swift SDK documentation for more configuration options and advanced topics.

Install the dependency

  1. Add the dependency to your Podfile:

    1pod 'AmplitudeSwift', '~> 1.0.0'
  2. Run pod install in the project directory.

  1. Navigate to File > Swift Package Manager > Add Package Dependency. This opens a dialog that allows you to add a package dependency.
  2. Enter the URL https://github.com/amplitude/Amplitude-Swift in the search bar.
  3. Xcode will automatically resolve to the latest version. Or you can select a specific version.
  4. Click the "Next" button to confirm the addition of the package as a dependency.
  5. Build your project to make sure the package is properly integrated.

Add the following line to your Cartfile.

1github "amplitude/Amplitude-Swift" ~> 1.0.0

Check out the Carthage docs for more info.

Install the Amplitude Analytics iOS SDK with CocoaPods, Carthage, or Swift Package Manager

Initialize the SDK

Before you instrument,initialize the SDK using the API Key for your Amplitude project.

Note

For EU data residency, the project must be set up inside Amplitude EU. Initialize the SDK with the API key from Amplitude EU.

1import AmplitudeSwift
2 
3let amplitude = Amplitude(
4 configuration: Configuration(
5 apiKey: "YOUR-API-KEY"
6 )
7)

Configure the serverZone property to configure your application to use European data residency.

1import AmplitudeSwift
2 
3let amplitude = Amplitude(
4 Configuration(
5 apiKey: "YOUR-API-KEY",
6 serverZone: ServerZone.EU
7 )
8)
1@import AmplitudeSwift;
2 
3AMPConfiguration* configuration = [AMPConfiguration initWithApiKey:@"YOUR-API-KEY"];
4Amplitude* amplitude = [Amplitude initWithConfiguration:configuration];

Configure the serverZone property to configure your application to use European data residency.

1@import AmplitudeSwift;
2 
3AMPConfiguration* configuration = [AMPConfiguration initWithApiKey:@"YOUR-API-KEY"];
4configuration.serverZone = AMPServerZoneEU;
5Amplitude* amplitude = [Amplitude initWithConfiguration:configuration];

Send data

Next, send data from your app or website to Amplitude.

1amplitude.track(
2 eventType: "Button Clicked",
3 eventProperties: ["my event prop key": "my event prop value"]
4)
1[amplitude track:@"Button Clicked" eventProperties:@{
2 @"my event prop key": @"my event prop value"
3}];

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.

1import AmplitudeSwift
2 
3let amplitude = Amplitude(
4 configuration: Configuration(
5 apiKey: "YOUR-API-KEY"
6 )
7)
8 
9amplitude.track(
10 eventType: "Button Clicked",
11 eventProperties: ["my event prop key": "my event prop value"]
12)
1@import AmplitudeSwift;
2 
3AMPConfiguration* configuration = [AMPConfiguration initWithApiKey:@"YOUR-API-KEY"];
4Amplitude* amplitude = [Amplitude initWithConfiguration:configuration];
5 
6[amplitude track:@"Button Clicked" eventProperties:@{
7 @"my event prop key": @"my event prop value"
8}];

For more information, see iOS Swift 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.

For more information, see Ampli for iOS Swift SDK or examples on GitHub for:

JRE

The JRE SDK sends events to Amplitude. For more information, see the JRE Java SDK documentation for more configuration options and advanced topics.

Install the dependency

If you use Gradle in your project, add the following dependency to build.gradle, and sync your project with the updated file.

1dependencies {
2 implementation 'org.json:json:20201115'
3 implementation 'com.amplitude:java-sdk:1.+'
4}

Download the latest JAR file then add it to the project's build path. See instructions for your IDE.

Initialize the SDK

Before you instrument,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.

Note

For EU data residency, the project must be set up inside Amplitude EU. Initialize the SDK with the API key from Amplitude EU.

1import com.amplitude.Amplitude;
2import org.json.JSONObject;
3 
4Amplitude amplitude = Amplitude.getInstance();
5amplitude.init(AMPLITUDE_API_KEY);

Configure the setServerUrl property to configure your application to use European data residency.

1import com.amplitude.Amplitude;
2import org.json.JSONObject;
3 
4Amplitude amplitude = Amplitude.getInstance();
5amplitude.init(AMPLITUDE_API_KEY);
6amplitude.setServerUrl("https://api.eu.amplitude.com/2/httpapi"); //[tl !~~]
1import com.amplitude.Amplitude
2import org.json.JSONObject
3 
4val amplitude = Amplitude.getInstance()
5amplitude.init(AMPLITUDE_API_KEY)

Configure the setServerUrl property to configure your application to use European data residency.

1import com.amplitude.Amplitude
2import org.json.JSONObject
3 
4val amplitude = Amplitude.getInstance()
5amplitude.init(AMPLITUDE_API_KEY)
6amplitude.setServerUrl("https://api.eu.amplitude.com/2/httpapi"); //[tl !~~]

Send data

Next, send data from your app or website to Amplitude.

1amplitude.logEvent(new Event("Button Clicked", "test_user_id"));
1amplitude.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.

1import com.amplitude.Amplitude;
2import org.json.JSONObject;
3 
4Amplitude amplitude = Amplitude.getInstance();
5amplitude.init(AMPLITUDE_API_KEY);
6 
7Event event = new Event("Button Clicked", "test_user_id");
8 
9JSONObject eventProps = new JSONObject();
10try {
11 eventProps.put("Hover Time", 10).put("prop_2", "value_2");
12} catch (JSONException e) {
13 System.err.println("Invalid JSON");
14 e.printStackTrace();
15}
16event.eventProperties = eventProps;
17 
18amplitude.logEvent(event);
1import com.amplitude.Amplitude
2import org.json.JSONObject
3 
4val amplitude = Amplitude.getInstance()
5amplitude.init(AMPLITUDE_API_KEY)
6 
7val eventProps= JSONObject()
8eventProps.put("Hover Time", 10).put("prop_2", "value_2")
9 
10val event = Event("Button Clicked", "test_user_id")
11event.eventProperties = eventProps
12 
13amplitude.logEvent(event)

For more information, see JRE 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.

For more information, see Ampli for Java SDK or examples on GitHub for:

1Ampli.getInstance().load();
2 
3Ampli.getInstance().yourEventType("ampli-user-id",
4 YourEventType.builder("Strongly typed property")
5 .stringProp()
6 .booleanProp(false)
7 .build()
8);
1Ampli.getInstance().load()
2 
3Ampli.getInstance().yourEventType("ampli-user-id",
4 YourEventType(
5 stringProp = "Strongly typed property",
6 booleanProp = false
7 )
8)

Python

The Python SDK sends events to Amplitude. For more information, see the Python SDK documentation for more configuration options and advanced topics.

Install the dependency

Install amplitude-analytics with pip:

1pip install amplitude-analytics

Initialize the SDK

Before you instrument,initialize the SDK using the API Key for your Amplitude project.

1from amplitude import Amplitude
2 
3amplitude = Amplitude(AMPLITUDE_API_KEY)

Note

For EU data residency, the project must be set up inside Amplitude EU. Initialize the SDK with the API key from Amplitude EU.

Configure server_zone when you initialize the client to send data to Amplitude's EU servers.

1from amplitude import Amplitude
2 
3amplitude = Amplitude(AMPLITUDE_API_KEY)
4amplitude.configuration.server_zone = 'EU' //[tl! ~~]

Send data

Next, send data from your app or website to Amplitude.

1from amplitude import BaseEvent
2 
3amplitude.track(
4 BaseEvent(
5 event_type="type of event",
6 user_id="USER_ID",
7 device_id="DEVICE_ID",
8 event_properties={
9 "source": "notification"
10 }
11 )
12)

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.

1from amplitude import Amplitude, Identify, BaseEvent
2 
3amplitude = Amplitude("AMPLITUDE_API_KEY")
4 
5identify_obj=Identify()
6identify_obj.set("location", "LAX")
7amplitude.identify(identify_obj)
8 
9amplitude.track(
10 BaseEvent(
11 event_type="type of event",
12 user_id="USER_ID",
13 device_id="DEVICE_ID",
14 event_properties={
15 "source": "notification"
16 }
17 )
18)
19 
20# Flush the event buffer
21amplitude.flush()
22 
23# Shutdown the client, recommend to call before program exit
24amplitude.shutdown()

For more information, see 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.

For more information, see Ampli for Python SDK or examples on GitHub for:

1ampli.load()
2 
3ampli.yourEventType(
4 "user_id",
5 YourEventType(
6 stringProp= "Strongly typed property",
7 booleanProp=True
8 )
9)

React Native

The React Native SDK sends events to Amplitude. For more information, see the React Native SDK documentation for more configuration options and advanced topics.

Install the dependency

1npm install @amplitude/analytics-react-native
2npm install @react-native-async-storage/async-storage
1yarn add @amplitude/analytics-react-native
2yarn add @react-native-async-storage/async-storage
1expo install @amplitude/analytics-react-native
2expo install @react-native-async-storage/async-storage

Install the native modules to run the SDK on iOS.

1cd ios
2pod install

Initialize the SDK

Before you instrument,initialize the SDK using the API Key for your Amplitude project.

1import { init } from '@amplitude/analytics-react-native';
2 
3init(AMPLITUDE_API_KEY, 'user@amplitude.com');
1import { init } from '@amplitude/analytics-react-native';
2 
3init(AMPLITUDE_API_KEY, 'user@amplitude.com');

Send data

Next, send data from your app or website to Amplitude.

1import { track } from '@amplitude/analytics-react-native';
2 
3const eventProperties = {
4 buttonColor: 'primary',
5};
6track('Button Clicked', eventProperties);
1import { track } from '@amplitude/analytics-react-native';
2 
3const eventProperties = {
4 buttonColor: 'primary',
5};
6track('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.

1import { init, track, Identify, identify } from '@amplitude/analytics-react-native';
2 
3init(AMPLITUDE_API_KEY, 'user@amplitude.com');
4 
5const identifyObj = new Identify();
6identifyObj.set('location', 'LAX');
7identify(identifyObj);
8 
9const eventProperties = {
10 buttonColor: 'primary',
11};
12track('Button Clicked', eventProperties);
1import { init, track, Identify, identify } from '@amplitude/analytics-react-native';
2 
3init(AMPLITUDE_API_KEY, 'user@amplitude.com');
4 
5const identifyObj = new Identify();
6identifyObj.set('location', 'LAX');
7identify(identifyObj);
8 
9const eventProperties = {
10 buttonColor: 'primary',
11};
12track('Button Clicked', eventProperties);

For more information, see 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.

For more information, see Ampli for the React Native SDK or examples on GitHub for:

1ampli.load();
2 
3ampli.yourEventType({
4 stringProp: 'Strongly typed property',
5});
1ampli.load();
2 
3ampli.yourEventType({
4 stringProp: 'Strongly typed property',
5});

Flutter

The Flutter SDK sends events to Amplitude. For more information, see the Flutter SDK documentation for more configuration options and advanced topics.

Install the dependency

1dependencies:
2 amplitude_flutter: ^3.13.0

For iOS installation, add platform :ios, '10.0' to your Podfile.

Initialize the SDK

Before you instrument,initialize the SDK using the API Key for your Amplitude project.

1import 'package:amplitude_flutter/amplitude.dart';
2 
3final Amplitude amplitude = Amplitude.getInstance();
4amplitude.init(AMPLITUDE_API_KEY);

Send data

Next, send data from your app or website to Amplitude.

1amplitude.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.

1import 'package:amplitude_flutter/amplitude.dart';
2import 'package:amplitude_flutter/identify.dart';
3 
4class YourClass {
5 Future<void> exampleForAmplitude() async {
6 final Amplitude amplitude = Amplitude.getInstance();
7 
8 amplitude.init(AMPLITUDE_API_KEY);
9 
10 final Identify identify1 = Identify();
11 identify1.setOnce('sign_up_date', '2015-08-24');
12 Amplitude.getInstance().identify(identify1);
13 
14 amplitude.logEvent('MyApp startup', eventProperties: {
15 'friend_num': 10,
16 'is_heavy_user': true
17 });
18}

For more information, see Flutter SDK.

Go

The Go SDK sends events to Amplitude. For more information, see the Go SDK documentation for more configuration options and advanced topics.

Install the dependency

1go get github.com/amplitude/analytics-go

Initialize the SDK

Before you instrument,initialize the SDK using the API Key for your Amplitude project.

1import (
2 "github.com/amplitude/analytics-go/amplitude"
3)
4 
5config := amplitude.NewConfig(AMPLITUDE_API_KEY)
6 
7client := amplitude.NewClient(config)

Send data

Next, send data from your app or website to Amplitude.

1client.Track(amplitude.Event{
2 EventType: "Button Clicked",
3 EventOptions: amplitude.EventOptions{
4 UserID: "user-id",
5 DeviceID: "device-id",
6 },
7 EventProperties: map[string]interface{}{"source": "notification"},
8})

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.

1package main
2 
3import (
4 "github.com/amplitude/analytics-go/amplitude"
5)
6 
7func main() {
8 config := amplitude.NewConfig(AMPLITUDE_API_KEY)
9 client := amplitude.NewClient(config)
10 
11 identifyObj := amplitude.Identify{}
12 identifyObj.Set("location", "LAX")
13 client.Identify(identifyObj, amplitude.EventOptions{UserID: "user-id"})
14 
15 client.Track(amplitude.Event{
16 EventType: "Button Clicked",
17 EventOptions: amplitude.EventOptions{
18 UserID: "user-id",
19 DeviceID: "device-id",
20 },
21 EventProperties: map[string]interface{}{"source": "notification"},
22 })
23}

For more information, see 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.

For more information, see Ampli for Go or examples on GitHub for:

1import "<your-module-name>/ampli"
2 
3ampli.Instance.Load(ampli.LoadOptions{
4 Client: ampli.LoadClientOptions{
5 Configuration: ampli.NewClientConfig(AMPLITUDE_API_KEY),
6 },
7})

Unity

The Unity SDK sends events to Amplitude. For more information, see the Unity SDK documentation for more configuration options and advanced topics.

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.

Install the dependency

  1. Make sure you have Git installed.
  2. In Unity, click Window > Package Manager.
  3. Click the plus + sign and select Add package from Git URL.
  4. Enter https://github.com/amplitude/unity-plugin.git?path=/Assets, and then click Add.
  5. The Unity editor imports the package from Git.
  1. Download the latest amplitude-unity.unitypackage from GitHub releases.
  2. Double click amplitude-unity.unitypackage to import the package into your Unity project.

Initialize the SDK

Before you instrument,initialize the SDK using the API Key for your Amplitude project.

1Amplitude amplitude = Amplitude.getInstance()
2amplitude.init("YOUR_API_KEY");

Send data

Next, send data from your app or website to Amplitude.

1import 'package:amplitude_flutter/amplitude.dart';
2 
3amplitude.logEvent('MyApp startup', eventProperties: {
4 'friend_num': 10,
5 'is_heavy_user': true
6});

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.

1Amplitude amplitude = Amplitude.getInstance();
2amplitude.init("AMPLITUDE_API_KEY");
3 
4amplitude.addUserProperty("oranges", 5);
5Dictionary<string, object> values = new Dictionary<string, object>();
6values.Add("Key A", "Value A");
7amplitude.addUserPropertyDict("user_facts", values);
8 
9JSONObjecteventProperties=newJSONObject().put("key", "value");
10Amplitude.getInstance().logEvent("initialize_game", eventProperties);

For more information, see Unity SDK.

Unreal

The Unreal SDK sends events to Amplitude. For more information, see the Unreal SDK documentation for more configuration options and advanced topics.

The Amplitude Analytics Unreal Engine SDK supports projects targeting iOS, MacOS, or tvOS.

Install the dependency

Install the Unreal Engine SDK by downloading the latest version of AmplitudeUnreal.zip found on the GitHub releases page. Unzip it into a folder inside your Unreal project's Plugins directory.

1mkdir -p Plugins/AmplitudeUnreal
2unzip AmplitudeUnreal.zip -d Plugins/AmplitudeUnreal

Initialize the SDK

Before you instrument,initialize the SDK using the API Key for your Amplitude project.

  1. In Unreal, navigate to Settings > Plugins > Project > Analytics to enable the plugin. Learn more about how to enable SDK plugin.
  2. Navigate to Settings -> Project Settings -> Analytics -> Providers to set Amplitude as your analytics provider. Learn more about how to set analytics provider.
  3. Navigate to Settings -> Project Settings -> Analytics -> Amplitude to set API keys. Learn more about how to set API keys.
  4. Add the following code:
1#include "Runtime/Analytics/Analytics/Public/Analytics.h"
2#include "Runtime/Analytics/Analytics/Public/Interfaces/IAnalyticsProvider.h"

Send data

Next, send data from your app or website to Amplitude.

1TArray<FAnalyticsEventAttribute> AppendedAttributes;
2AppendedAttributes.Emplace(TEXT("Test Event Prop key1"), TEXT("Test Event value1"));
3AppendedAttributes.Emplace(TEXT("Test Event Prop key2"), TEXT("Test Event value2"));
4FAnalytics::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.

1FAnalytics::Get().GetDefaultConfiguredProvider()->SetLocation(TEXT("Test location"));
2FAnalytics::Get().GetDefaultConfiguredProvider()->SetGender(TEXT("Test gender"));
3FAnalytics::Get().GetDefaultConfiguredProvider()->SetAge(TEXT(27));
4 
5TArray<FAnalyticsEventAttribute> AppendedAttributes;
6AppendedAttributes.Emplace(TEXT("Test Event Prop key1"), TEXT("Test Event value1"));
7AppendedAttributes.Emplace(TEXT("Test Event Prop key2"), TEXT("Test Event value2"));
8FAnalytics::Get().GetDefaultConfiguredProvider()->RecordEvent(TEXT("Game Started"), AppendedAttributes);

For more information, see Unreal SDK.

Was this page helpful?

Thanks for your feedback!

July 11th, 2024

Need help? Contact Support

Visit Amplitude.com

Have a look at the Amplitude Blog

Learn more at Amplitude Academy

© 2024 Amplitude, Inc. All rights reserved. Amplitude is a registered trademark of Amplitude, Inc.