Tracking Events in Third Party Websites
You can use Analytics Cloud to track events for analysis on websites not built on Liferay DXP.
Connecting Analytics Cloud to a Third Party Website
Adding Analytics Cloud to a non-Liferay DXP website involves only adding some JavaScript code to the <head>
and <body>
of your HTML pages:
-
Add this script declaration to the
<head>
of any page you want to track using Analytics Cloud: -
Add this script to the
<body>
of any page you want to track using Analytics Cloud:
For example, here’s a complete index.html
file with a sample script to establish a connection:
The client makes a connection using the Analytics.create()
method. This requires four values from your Analytics Cloud workspace:
-
PROPERTY_ID
: On your Analytics Cloud settings page, click Properties in the sidebar. Copy the Property ID of the property you want to use or create a new property. -
DATA_SOURCE_ID
: On your Analytics Cloud settings page, click Data Sources in the sidebar. Click on the data source you want to use and copy the DXP Image ID. -
THE_REGION_KEY
: To obtain the region key, contact Analytics Cloud support. -
WEDEPLOY_KEY
: To obtain the WeDeploy key, contact Analytics Cloud support.
Tracking Events
Tracking pages and assets in third-party websites works similarly to tracking custom events in Liferay DXP. You can create an event to send to Analytics Cloud using the Analytics.track()
method.
You can identify a user through the Analytics.setIdentity()
method. Without this method, Analytics Cloud can’t track users outside of DXP and attributes all events to anonymous users.
You can call this function on a successful login to track everything users do when logged into their accounts.