The SAP Customer Data Cloud Web SDK provides a JavaScript library that simplifies the integration of SAP Customer Data Cloud functionalities into web applications.
It acts as a wrapper around the SAP Customer Data Cloud's REST API, making it easier to manage user identities and access user data.

Where <DC> is:
us1.gigya.com - For the US data center.
eu1.gigya.com - For the European data center.
au1.gigya.com - For the Australian data center.
eu2.gigya.com - For the European Azure data center.
cn1.sapcdm.cn - For the Chinese data center.
global.gigya.com - For all Global sites or site groups.
Alternatively, when loading the Web SDK on US, EU or AU sites, or when using the global domain, you can use the following structure:
1<script type="text/javascript" lang="javascript" src="https://cdns.gigya.com/js/gigya.js?apikey=<A_Valid_API_Key_For_Your_Site>"></script>The gigya.jssrc (source) must be loaded in the <head> of every page within your website or webapp that uses SAP Customer Data Cloud services and should be the first element, whenever possible. And it should only be called once on any page.
By including gigya.js in your code, your JavaScript code gets access to the gigya.* JavaScript API namespace.
Core Methods of the Web SDK
The Web SDK offers a range of methods organized under different namespaces such as gigya.socialize, gigya.accounts, gigya.ds, etc. thus, all methods are referenced with the gigya. prefix.

All the methods in the SAP Customer Data Cloud Web SDK have a common signature:
gigya.<namespace>.<method_name>(params);
For example, gigya.socialize.showShareBarUI(params)
The params object is a Javascript object that may contain multiple member fields.
To implement Customer Identity manually via Javascript (without the use of any module, cartridge, plugin, etc.), we need to master four methods offered by the Web SDK:
gigya.accounts.showScreenset(): Injects the HTML code of a screen-set into the webpage's DOM, allowing you to display registration, login, and profile update forms. Screen-sets are pre-built UI components that handle common identity management tasks.
gigya.accounts.addEventHandler(): Listens for user login and logout events, enabling you to trigger actions based on these events. This allows you to customize the user experience based on their authentication status.
gigya.accounts.getAccountInfo(): Checks for an active user session and provides access to the user's profile data if a session exists. A response.errorCode of 0 indicates that a user is logged in.
gigya.accounts.logout(): Logs the user out of the current session. This ensures that user sessions are properly terminated when the user is finished.
Note
For SAP Customer Data Cloud Web SDK methods to function properly, they can only be called after the SAP Customer Data Cloud Web SDK finishes loading altogether.
To ensure that the SAP Customer Data Cloud Web SDK is always loaded before any method calls on your webpage, you can place all SAP Customer Data Cloud-related Javascript functions inside a handler and then call that handler using the onGigyaServiceReady variable. It is a variable that the SAP Customer Data Cloud Web SDK always checks for as soon as it completes loading.
Handling Events for the Web SDK
The SAP Customer Data Cloud service generates many events driven by user interactions such as user login, button clicks, etc. It also generates global application events whenever they occur, regardless of the action that triggered the event.
Applications may register event handlers that listen for particular events and execute code when these events are received.

These are the available global application events:
onLogin - Fired when a user successfully logs in to SAP Customer Data Cloud.
onLogout - Fired when a user logs out from SAP Customer Data Cloud.
onConnectionAdded - Fired when a user is connected to a provider.
onConnectionRemoved - Fired when a user is disconnected from a provider.
onError - Fired if an error occurs when loading the Web SDK.
Here’s an example code snippet for defining and registering event handlers using the Web SDK.

Having defined an event handler, you can register it for an event using the accounts.addEventHandlers or socialize.addEventHandlers Web SDK methods. Like any other Web SDK method, addEventHandlers receives the params object.
You may register one event handler (one function) for several events and several events within one addEventHandlers method call.
For more information, refer to the Events documentation in the SAP Help Portal.


