-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[angular][xmcloud] Init CloudSDK on browser (#1952)
* [angular][xmcloud] Init CloudSDK on browser * PR followup * fix events init * correct cloudsdk package in nextjs
- Loading branch information
1 parent
83e7e83
commit 27e39a8
Showing
5 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...ore-jss/src/templates/angular-xmcloud/src/app/routing/scripts/cloud-sdk-init.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { CloudSDK } from '@sitecore-cloudsdk/core/browser'; | ||
import '@sitecore-cloudsdk/events/browser'; | ||
import { environment } from '../../../environments/environment'; | ||
import { isServer } from '@sitecore-jss/sitecore-jss-angular'; | ||
|
||
/** | ||
* Component to init CloudSDK logic - to allow events throughout the site | ||
*/ | ||
@Component({ | ||
selector: 'app-cloud-sdk-init', | ||
template: '', | ||
}) | ||
export class CloudSdkInitComponent implements OnInit { | ||
constructor() {} | ||
|
||
ngOnInit(): void { | ||
if (!isServer) { | ||
CloudSDK({ | ||
siteName: environment.sitecoreSiteName, | ||
sitecoreEdgeUrl: environment.sitecoreEdgeUrl, | ||
sitecoreEdgeContextId: environment.sitecoreEdgeContextId, | ||
// Replace with the top level cookie domain of the website that is being integrated e.g ".example.com" and not "www.example.com" | ||
cookieDomain: window.location.hostname.replace(/^www\./, ''), | ||
// Cookie may be created in personalize middleware (server), but if not we should create it here | ||
enableBrowserCookie: true, | ||
}) | ||
.addEvents() | ||
.initialize(); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...sitecore-jss/src/templates/angular-xmcloud/src/app/routing/scripts/scripts.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<ng-container> | ||
<sc-editing-scripts></sc-editing-scripts> | ||
<app-cloud-sdk-init></app-cloud-sdk-init> | ||
</ng-container> |
3 changes: 2 additions & 1 deletion
3
...eate-sitecore-jss/src/templates/angular-xmcloud/src/app/routing/scripts/scripts.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { ScriptsComponent } from './scripts.component'; | ||
import { JssModule } from '@sitecore-jss/sitecore-jss-angular'; | ||
import { CloudSdkInitComponent } from './cloud-sdk-init.component'; | ||
|
||
@NgModule({ | ||
exports: [ScriptsComponent], | ||
imports: [JssModule], | ||
declarations: [ScriptsComponent], | ||
declarations: [ScriptsComponent, CloudSdkInitComponent], | ||
}) | ||
export class ScriptsModule {} |