create-sitecore-jss 22.2.0-canary.78 → 22.2.0-canary.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/templates/angular-xmcloud/.env +7 -0
- package/dist/templates/angular-xmcloud/src/app/routing/scripts/cdp-page-view.component.ts +77 -0
- package/dist/templates/angular-xmcloud/src/app/routing/scripts/cloud-sdk-init.component.ts +3 -3
- package/dist/templates/angular-xmcloud/src/app/routing/scripts/scripts.component.html +1 -0
- package/dist/templates/angular-xmcloud/src/app/routing/scripts/scripts.module.ts +2 -1
- package/package.json +2 -2
|
@@ -12,3 +12,10 @@ PROXY_HOST=http://localhost:3000
|
|
|
12
12
|
|
|
13
13
|
# Your XM Cloud Proxy server path is needed to build the app. The build output will be copied to the proxy server path.
|
|
14
14
|
PROXY_BUILD_PATH=<%- locals.relativeProxyAppDestination.replace(/\\/g, '\\\\') %>dist
|
|
15
|
+
|
|
16
|
+
# ==============================================
|
|
17
|
+
|
|
18
|
+
# An optional Sitecore Personalize scope identifier.
|
|
19
|
+
# This can be used to isolate personalization data when multiple XM Cloud Environments share a Personalize tenant.
|
|
20
|
+
# This should match the PAGES_PERSONALIZE_SCOPE environment variable for your connected XM Cloud Environment.
|
|
21
|
+
PERSONALIZE_SCOPE=
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
2
|
+
import { Subscription } from 'rxjs';
|
|
3
|
+
import { isServer, CdpHelper, LayoutServicePageState } from '@sitecore-jss/sitecore-jss-angular';
|
|
4
|
+
import { pageView, PageViewData } from '@sitecore-cloudsdk/events/browser';
|
|
5
|
+
import { JssContextService } from '../../jss-context.service';
|
|
6
|
+
import { JssState } from '../../JssState';
|
|
7
|
+
import { environment } from '../../../environments/environment';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* This is the CDP page view component.
|
|
11
|
+
* It uses the Sitecore Cloud SDK to enable page view events on the client-side.
|
|
12
|
+
* See Sitecore Cloud SDK documentation for details.
|
|
13
|
+
* https://www.npmjs.com/package/@sitecore-cloudsdk/events
|
|
14
|
+
*/
|
|
15
|
+
@Component({
|
|
16
|
+
selector: 'app-cdp-page-view',
|
|
17
|
+
template: '',
|
|
18
|
+
})
|
|
19
|
+
export class CdpPageViewComponent implements OnInit, OnDestroy {
|
|
20
|
+
private contextSubscription: Subscription;
|
|
21
|
+
|
|
22
|
+
constructor(private jssContext: JssContextService) {}
|
|
23
|
+
|
|
24
|
+
ngOnInit(): void {
|
|
25
|
+
if (!isServer()) {
|
|
26
|
+
this.contextSubscription = this.jssContext.state.subscribe((newState: JssState) => {
|
|
27
|
+
const {
|
|
28
|
+
route,
|
|
29
|
+
context: { pageState, language, variantId },
|
|
30
|
+
} = newState.sitecore;
|
|
31
|
+
|
|
32
|
+
// Do not create events in editing or preview mode or if missing route data
|
|
33
|
+
if (pageState !== LayoutServicePageState.Normal || !route?.itemId) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Do not create events if disabled (e.g. we don't have consent)
|
|
38
|
+
if (this.disabled()) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const scope = process.env.PERSONALIZE_SCOPE;
|
|
43
|
+
const pageVariantId = CdpHelper.getPageVariantId(
|
|
44
|
+
route.itemId,
|
|
45
|
+
language || environment.defaultLanguage,
|
|
46
|
+
variantId as string,
|
|
47
|
+
scope
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const pageViewData: PageViewData = {
|
|
51
|
+
channel: 'WEB',
|
|
52
|
+
currency: 'USD',
|
|
53
|
+
page: route.name,
|
|
54
|
+
pageVariantId,
|
|
55
|
+
language,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
pageView(pageViewData).catch((err) => console.debug(err));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
ngOnDestroy() {
|
|
64
|
+
if (this.contextSubscription) {
|
|
65
|
+
this.contextSubscription.unsubscribe();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Determines if the page view events should be turned off.
|
|
71
|
+
* IMPORTANT: You should implement based on your cookie consent management solution of choice.
|
|
72
|
+
* By default it is disabled if not in production mode
|
|
73
|
+
*/
|
|
74
|
+
disabled = () => {
|
|
75
|
+
return !environment.production;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -15,7 +15,7 @@ export class CloudSdkInitComponent implements OnInit {
|
|
|
15
15
|
constructor() {}
|
|
16
16
|
|
|
17
17
|
ngOnInit(): void {
|
|
18
|
-
if (!isServer) {
|
|
18
|
+
if (!isServer() && environment.production) {
|
|
19
19
|
CloudSDK({
|
|
20
20
|
siteName: environment.sitecoreSiteName,
|
|
21
21
|
sitecoreEdgeUrl: environment.sitecoreEdgeUrl,
|
|
@@ -25,8 +25,8 @@ export class CloudSdkInitComponent implements OnInit {
|
|
|
25
25
|
// Cookie may be created in personalize middleware (server), but if not we should create it here
|
|
26
26
|
enableBrowserCookie: true,
|
|
27
27
|
})
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
.addEvents()
|
|
29
|
+
.initialize();
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -2,10 +2,11 @@ import { NgModule } from '@angular/core';
|
|
|
2
2
|
import { ScriptsComponent } from './scripts.component';
|
|
3
3
|
import { JssModule } from '@sitecore-jss/sitecore-jss-angular';
|
|
4
4
|
import { CloudSdkInitComponent } from './cloud-sdk-init.component';
|
|
5
|
+
import { CdpPageViewComponent } from './cdp-page-view.component';
|
|
5
6
|
|
|
6
7
|
@NgModule({
|
|
7
8
|
exports: [ScriptsComponent],
|
|
8
9
|
imports: [JssModule],
|
|
9
|
-
declarations: [ScriptsComponent, CloudSdkInitComponent],
|
|
10
|
+
declarations: [ScriptsComponent, CloudSdkInitComponent, CdpPageViewComponent],
|
|
10
11
|
})
|
|
11
12
|
export class ScriptsModule {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-sitecore-jss",
|
|
3
|
-
"version": "22.2.0-canary.
|
|
3
|
+
"version": "22.2.0-canary.79",
|
|
4
4
|
"description": "Sitecore JSS initializer",
|
|
5
5
|
"bin": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"ts-node": "^10.9.1",
|
|
64
64
|
"typescript": "~4.9.5"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "c3625aea93712fdec9a17d5938111c540e2ad401"
|
|
67
67
|
}
|