Skip to content

Commit

Permalink
[Angular] Expose tracking functionality and remove direct usage of `s…
Browse files Browse the repository at this point in the history
…itecore-jss` module (#1048)

* [Angular] Expose tracking functionality and remove direct usage of `sitecore-jss` module

* Fix lint issue
  • Loading branch information
illiakovalenko authored May 31, 2022
1 parent ffdf480 commit e9bff66
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
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';

0 comments on commit e9bff66

Please sign in to comment.