The Page URL Enrichment plugin automatically adds page URL-related properties to all events tracked by the Browser SDK. This plugin enhances your event data with contextual information about the current page and previous page navigation. This lets you better understand user journeys and page transitions.
When using the plugin, remember:
This package is available on the npm registry for installation using npm
and yarn
.
# npm
npm install @amplitude/plugin-page-url-enrichment-browser
# yarn
yarn add @amplitude/plugin-page-url-enrichment-browser
This plugin works on top of Amplitude Browser SDK and adds page URL enrichment properties to all events. To use this plugin, you must be using @amplitude/analytics-browser
version v2.0.0
or later.
import * as amplitude from '@amplitude/analytics-browser';
import { pageUrlEnrichmentPlugin } from '@amplitude/plugin-page-url-enrichment-browser';
The plugin accepts an optional parameter of type Object
to configure the plugin.
const pageUrlEnrichment = pageUrlEnrichmentPlugin();
amplitude.add(pageUrlEnrichment);
amplitude.init('API_KEY');
This plugin adds the following properties to all events:
Property | Description |
---|---|
[Amplitude] Page Domain |
The website's hostname (location.hostname ) |
[Amplitude] Page Location |
The website's full URL (location.href ) |
[Amplitude] Page Path |
The website's pathname (location.pathname ) |
[Amplitude] Page Title |
The website's title (document.title ) |
[Amplitude] Page URL |
The website's URL excluding query parameters. |
[Amplitude] Previous Page Location |
The URL of the previous page the user visited. |
[Amplitude] Previous Page Type |
A classification of the previous page type. |
The [Amplitude] Previous Page Type
property classifies the previous page based on the following logic:
direct
: No previous page or referrer (user came directly to the site).internal
: Previous page was from the same domain (same hostname).external
: Previous page was from a different domain.The Page URL Enrichment plugin:
pushState
, replaceState
, and popstate
events to detect page changes in single-page applications.The plugin uses session storage to persist navigation information across page changes. The plugin stores data using these keys:
AMP_URL_INFO
: Stores the current and previous page URLs.This ensures that previous page information persists during single-page application navigation or page refreshes within the same session.
Here's a complete example of how to set up the Page URL Enrichment plugin:
import * as amplitude from '@amplitude/analytics-browser';
import { pageUrlEnrichmentPlugin } from '@amplitude/plugin-page-url-enrichment-browser';
// Create the plugin instance
const pageUrlEnrichment = pageUrlEnrichmentPlugin();
// Add the plugin to Amplitude
amplitude.add(pageUrlEnrichment);
// Initialize Amplitude
amplitude.init('YOUR_API_KEY');
// Track an event - it will automatically include page URL properties
amplitude.track('Button Clicked', {
button_name: 'Sign Up'
});
The tracked event includes properties like:
{
"event_type": "Button Clicked",
"event_properties": {
"button_name": "Sign Up",
"[Amplitude] Page Domain": "example.com",
"[Amplitude] Page Location": "https://example.com/signup?utm_source=google",
"[Amplitude] Page Path": "/signup",
"[Amplitude] Page Title": "Sign Up - Example",
"[Amplitude] Page URL": "https://example.com/signup",
"[Amplitude] Previous Page Location": "https://example.com/home",
"[Amplitude] Previous Page Type": "internal"
}
}
August 4th, 2024
Need help? Contact Support
Visit Amplitude.com
Have a look at the Amplitude Blog
Learn more at Amplitude Academy
© 2025 Amplitude, Inc. All rights reserved. Amplitude is a registered trademark of Amplitude, Inc.