Skip to content
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] Expose tracking functionality and remove direct usage of sitecore-jss module #1048

Merged
merged 2 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Component, Input, OnInit } from '@angular/core';
import { ComponentRendering } from '@sitecore-jss/sitecore-jss-angular';
import { trackingApi, TrackingRequestOptions } from '@sitecore-jss/sitecore-jss/tracking';
import {
ComponentRendering,
trackingApi,
TrackingRequestOptions,
} from '@sitecore-jss/sitecore-jss-angular';
import { environment } from '../../../environments/environment';
import { JssDataFetcherService } from '../../jss-data-fetcher.service';

Expand Down Expand Up @@ -42,14 +45,14 @@ export class StyleguideTrackingComponent implements OnInit {
trackingApi
.trackEvent([{ eventId: this.event }], this.trackingApiOptions)
.then(() => alert('Page event pushed'))
.catch((error) => alert(error));
.catch((error: unknown) => alert(error));
}

submitGoal() {
trackingApi
.trackEvent([{ goalId: this.goal }], this.trackingApiOptions)
.then(() => alert('Goal pushed'))
.catch((error) => alert(error));
.catch((error: unknown) => alert(error));
}

submitOutcome() {
Expand All @@ -65,14 +68,14 @@ export class StyleguideTrackingComponent implements OnInit {
this.trackingApiOptions
)
.then(() => alert('Outcome pushed'))
.catch((error) => alert(error));
.catch((error: unknown) => alert(error));
}

triggerCampaign() {
trackingApi
.trackEvent([{ campaignId: this.campaign }], this.trackingApiOptions)
.then(() => alert('Campaign set'))
.catch((error) => alert(error));
.catch((error: unknown) => alert(error));
}

submitPageView() {
Expand All @@ -82,7 +85,7 @@ export class StyleguideTrackingComponent implements OnInit {
this.trackingApiOptions
)
.then(() => alert('Page view pushed'))
.catch((error) => alert(error));
.catch((error: unknown) => alert(error));
}

abandonSession() {
Expand All @@ -94,7 +97,7 @@ export class StyleguideTrackingComponent implements OnInit {
trackingApi
.trackEvent([], abandonOptions)
.then(() => alert('Interaction has been terminated and its data pushed to xConnect.'))
.catch((error) => alert(error));
.catch((error: unknown) => alert(error));
}

submitBatching() {
Expand All @@ -111,6 +114,6 @@ export class StyleguideTrackingComponent implements OnInit {
this.trackingApiOptions
)
.then(() => alert('Batch of events pushed'))
.catch((error) => alert(error));
.catch((error: unknown) => alert(error));
}
}
9 changes: 9 additions & 0 deletions packages/sitecore-jss-angular/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,12 @@ export {
resetEditorChromes,
handleEditorAnchors,
} from '@sitecore-jss/sitecore-jss/utils';
export {
trackingApi,
TrackingRequestOptions,
CampaignInstance,
GoalInstance,
OutcomeInstance,
EventInstance,
PageViewInstance,
} from '@sitecore-jss/sitecore-jss/tracking';