What is amplitude-js?
The amplitude-js npm package is a JavaScript library for integrating Amplitude's analytics platform into web applications. It allows developers to track user interactions, events, and behaviors to gain insights into user engagement and product usage.
What are amplitude-js's main functionalities?
Initialize Amplitude
This feature initializes the Amplitude instance with your API key, allowing you to start tracking events and user interactions.
const amplitude = require('amplitude-js');
amplitude.getInstance().init('YOUR_API_KEY');
Track Events
This feature allows you to log custom events with optional event properties. It helps in tracking specific user actions within your application.
amplitude.getInstance().logEvent('EVENT_NAME', { key: 'value' });
Identify Users
This feature sets a unique user ID for tracking individual users. It is useful for identifying and analyzing user-specific behaviors.
amplitude.getInstance().setUserId('USER_ID');
Set User Properties
This feature allows you to set custom properties for a user, which can be used for segmentation and more detailed analysis.
amplitude.getInstance().setUserProperties({ key: 'value' });
Revenue Tracking
This feature enables revenue tracking by logging transactions and purchases, helping you understand the financial impact of user actions.
const revenue = new amplitude.Revenue().setProductId('PRODUCT_ID').setPrice(9.99);
amplitude.getInstance().logRevenueV2(revenue);
Other packages similar to amplitude-js
mixpanel-browser
Mixpanel is another popular analytics platform that offers similar functionalities to Amplitude, such as event tracking, user identification, and property setting. Mixpanel also provides advanced features like A/B testing and user retention analysis.
google-analytics
Google Analytics is a widely-used analytics service that tracks and reports website traffic. While it offers robust event tracking and user analysis features, it is more focused on web traffic and marketing analytics compared to Amplitude's product analytics.
Official Amplitude JS/Web SDK
A JavaScript SDK for tracking events and revenue to Amplitude.
Amplitude and Ampli SDK
Ampli SDK is autogenerated library based on your pre-defined tracking plan. The Ampli SDK, is a lightweight wrapper over the Amplitude SDK that provides type-safety, supports linting, and enables features like input validation. The code replicates the spec in the Tracking Plan and enforces its rules and requirements. This repository is about Amplitude SDK. To learn more about Ampli SDK, please refer to the Ampli Browser and examples.
Installation and Quick Start
Demo Pages
- A demo page showing a simple integration on a web page.
- A demo page showing an integration using RequireJS.
- A demo page demonstrating a potential integration with Google Tag Manager.
Deprecated - React Native
As of >= v8.0.0, this SDK no longer has support for React Native. We recently released a new SDK focused on providing a React Native first approach to using Amplitude in cross-platform projects. Amplitude React Native SDK
Previously used amplitude-js and looking to migrate to @amplitude/react-native?
Node.js
Please visit Amplitude-Node for our Node SDK.
Changelog
Click here to view the JavaScript SDK Changelog.
Upgrading Major Versions and Breaking Changes
6.0
The cookie format has been changed to be more compact. If you use the same
Amplitude project(API key) across multiple applications, and you track
anonymous users across those applications, you will want to update amplitude
across all those applications at the same time. Otherwise these anonymous users
will have a different device id in your different applications.
If you do not have multiple installations of amplitude, or if you do not track
anonymous users across different installations of amplitude, this change should
not affect you.
5.0
We stopped committing the generated amplitude.min.js and amplitude.js files to
the repository. This should only affect you if you load amplitude via github.
You should use npm
or yarn
instead.
We dropped our custom symbian and blackberry user agent parsing to simply match
what the ua-parser-js library does.
4.0
The library now defaults to sending requests to https://api.amplitude.com
instead of //api.amplitude.com. This should only affect you if your site does
not use https and you use a Content Security Policy.
Need Help?
If you have any problems or issues over our SDK, feel free to create a github issue or submit a request on Amplitude Help.