-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[angular][xmcloud] CDP page view component #1957
Merged
Merged
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f1f68ed
remove duplicate changelog entry
yavorsk 4426395
add cdp page view component to send page view events
yavorsk c03ae78
minor update of imports
yavorsk f691b45
update changelog
yavorsk ad2d40f
some fixes - handle empty language, handle send event error;
yavorsk 0bd1ec0
do not initialize csdk and send events if not in production mode
yavorsk 1b3ed48
add comment
yavorsk 0807264
fix comment intendation
yavorsk 0eea61c
minor update of changelog entry
yavorsk e5e4fc4
rename personalize scop environment variable
yavorsk 9c5fd45
Merge branch 'feature/jss-3977' of https://github.com/Sitecore/jss in…
yavorsk 30a1932
Merge branch 'dev' into feature/JSS-3977
yavorsk 86bd63d
add migration guide entry for page view tracking
yavorsk 9daabd1
add migrate guide for cloud sdk init
yavorsk d6cb0f5
update changelog
yavorsk c6a7f7b
remove 'public' prefix of the personalize scope env variable
yavorsk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
77 changes: 77 additions & 0 deletions
77
...core-jss/src/templates/angular-xmcloud/src/app/routing/scripts/cdp-page-view.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,77 @@ | ||
import { Component, OnInit, OnDestroy } from '@angular/core'; | ||
import { Subscription } from 'rxjs'; | ||
import { isServer, CdpHelper, LayoutServicePageState } from '@sitecore-jss/sitecore-jss-angular'; | ||
import { pageView, PageViewData } from '@sitecore-cloudsdk/events/browser'; | ||
import { JssContextService } from '../../jss-context.service'; | ||
import { JssState } from '../../JssState'; | ||
import { environment } from '../../../environments/environment'; | ||
|
||
/** | ||
* This is the CDP page view component. | ||
* It uses the Sitecore Cloud SDK to enable page view events on the client-side. | ||
* See Sitecore Cloud SDK documentation for details. | ||
* https://www.npmjs.com/package/@sitecore-cloudsdk/events | ||
*/ | ||
@Component({ | ||
selector: 'app-cdp-page-view', | ||
template: '', | ||
}) | ||
export class CdpPageViewComponent implements OnInit, OnDestroy { | ||
private contextSubscription: Subscription; | ||
|
||
constructor(private jssContext: JssContextService) {} | ||
|
||
ngOnInit(): void { | ||
if (!isServer()) { | ||
this.contextSubscription = this.jssContext.state.subscribe((newState: JssState) => { | ||
const { | ||
route, | ||
context: { pageState, language, variantId }, | ||
} = newState.sitecore; | ||
|
||
yavorsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Do not create events in editing or preview mode or if missing route data | ||
if (pageState !== LayoutServicePageState.Normal || !route?.itemId) { | ||
return; | ||
} | ||
|
||
// Do not create events if disabled (e.g. we don't have consent) | ||
if (this.disabled()) { | ||
return; | ||
} | ||
|
||
const scope = process.env.ANGULAR_PUBLIC_PERSONALIZE_SCOPE; | ||
const pageVariantId = CdpHelper.getPageVariantId( | ||
route.itemId, | ||
language || environment.defaultLanguage, | ||
variantId as string, | ||
scope | ||
); | ||
|
||
const pageViewData: PageViewData = { | ||
channel: 'WEB', | ||
currency: 'USD', | ||
page: route.name, | ||
pageVariantId, | ||
language, | ||
}; | ||
|
||
pageView(pageViewData).catch((err) => console.debug(err)); | ||
}); | ||
} | ||
} | ||
|
||
ngOnDestroy() { | ||
if (this.contextSubscription) { | ||
this.contextSubscription.unsubscribe(); | ||
} | ||
} | ||
|
||
/** | ||
* Determines if the page view events should be turned off. | ||
* IMPORTANT: You should implement based on your cookie consent management solution of choice. | ||
* By default it is disabled if not in production mode | ||
*/ | ||
disabled = () => { | ||
return !environment.production; | ||
}; | ||
} |
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
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,4 +1,5 @@ | ||
<ng-container> | ||
<sc-editing-scripts></sc-editing-scripts> | ||
<app-cloud-sdk-init></app-cloud-sdk-init> | ||
<app-cdp-page-view></app-cdp-page-view> | ||
</ng-container> |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one requires migration guide as well. You can ping @art-alexeyenko to add it