There are two ways to register goals from JavaScript that I am aware of:
Federated Experience Manager
Sitecore FXM allows you to make visits and trigger events from external websites.
There's an FXM feature (that is not commonly used), allowing you to combine simultaneous site visits from the same browser into a single interaction. Visits will be combined even if one visit was on your Sitecore website, and the other on an external FXM-powered website. You should enable this feature with the setting FXM.ShareSessionsWhenPossible
located in Sitecore.FXM.config
.
Since your "external" site will actually be your Sitecore instance, it will be hosted on the same domain name, and hence, all FXM API calls will be treated as the same logical visit. In other words, you shouldn't be worried about this compatibility table.
Once you set up FXM, you can record goals using the following FXM code:
SCBeacon.trackGoal(“Goal name”);
You can find more API details on this official documentation page:
https://doc.sitecore.net/sitecore_experience_platform/digital_marketing/federated_experience_manager/configuring/fxm_javascript_api
Custom web endpoint
If using FXM wouldn't work for you, then you should use the server-side goal registration API. You will need to expose it as a web service endpoint (WebAPI, MVC, .ashx, whatever suits you best).
Here's the proper way to register a goal server-side:
if (Sitecore.Analytics.Tracker.IsActive)
{
if (Sitecore.Analytics.Tracker.Current.CurrentPage != null)
{
var goalId = new Sitecore.Data.ID("{INSERT-GOAL-ID-HERE}");
Sitecore.Analytics.Data.Items.PageEventItem goalToTrigger =
Sitecore.Analytics.Tracker.DefinitionItems.PageEvents[goalId];
if (goalToTrigger != null)
{
Sitecore.Analytics.Model.PageEventData eventData =
Sitecore.Analytics.Tracker.Current.CurrentPage.Register(goalToTrigger);
}
else
{
Sitecore.Diagnostics.Log.Error("Goal with ID " + goalId + " does not exist", this);
}
}
else
{
Sitecore.Diagnostics.Log.Error("Tracker.Current.CurrentPage is null", this);
}
}
else
{
Sitecore.Diagnostics.Log.Warn("The tracker is not active. Unable to register the goal.", this);
}