From f8becced3dfa15ebb747e93fa5758ea6116de3ab Mon Sep 17 00:00:00 2001 From: illiakovalenko Date: Tue, 31 May 2022 15:48:28 +0300 Subject: [PATCH 1/2] [Angular] Expose tracking functionality and remove direct usage of `sitecore-jss` module --- .../styleguide-tracking.component.ts | 17 ++++++++--------- packages/sitecore-jss-angular/src/public_api.ts | 9 +++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/create-sitecore-jss/src/templates/angular/src/app/components/styleguide-tracking/styleguide-tracking.component.ts b/packages/create-sitecore-jss/src/templates/angular/src/app/components/styleguide-tracking/styleguide-tracking.component.ts index 23dba8f492..7e2e797fb0 100644 --- a/packages/create-sitecore-jss/src/templates/angular/src/app/components/styleguide-tracking/styleguide-tracking.component.ts +++ b/packages/create-sitecore-jss/src/templates/angular/src/app/components/styleguide-tracking/styleguide-tracking.component.ts @@ -1,6 +1,5 @@ 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'; @@ -42,14 +41,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() { @@ -65,14 +64,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() { @@ -82,7 +81,7 @@ export class StyleguideTrackingComponent implements OnInit { this.trackingApiOptions ) .then(() => alert('Page view pushed')) - .catch((error) => alert(error)); + .catch((error: unknown) => alert(error)); } abandonSession() { @@ -94,7 +93,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() { @@ -111,6 +110,6 @@ export class StyleguideTrackingComponent implements OnInit { this.trackingApiOptions ) .then(() => alert('Batch of events pushed')) - .catch((error) => alert(error)); + .catch((error: unknown) => alert(error)); } } diff --git a/packages/sitecore-jss-angular/src/public_api.ts b/packages/sitecore-jss-angular/src/public_api.ts index 7b07036382..e54a76b4fe 100644 --- a/packages/sitecore-jss-angular/src/public_api.ts +++ b/packages/sitecore-jss-angular/src/public_api.ts @@ -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'; From 8ffff297f8734e7e5694bbdfa90da061a442b8bc Mon Sep 17 00:00:00 2001 From: illiakovalenko Date: Tue, 31 May 2022 15:49:04 +0300 Subject: [PATCH 2/2] Fix lint issue --- .../styleguide-tracking/styleguide-tracking.component.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/create-sitecore-jss/src/templates/angular/src/app/components/styleguide-tracking/styleguide-tracking.component.ts b/packages/create-sitecore-jss/src/templates/angular/src/app/components/styleguide-tracking/styleguide-tracking.component.ts index 7e2e797fb0..346c1466d9 100644 --- a/packages/create-sitecore-jss/src/templates/angular/src/app/components/styleguide-tracking/styleguide-tracking.component.ts +++ b/packages/create-sitecore-jss/src/templates/angular/src/app/components/styleguide-tracking/styleguide-tracking.component.ts @@ -1,5 +1,9 @@ import { Component, Input, OnInit } from '@angular/core'; -import { ComponentRendering, trackingApi, TrackingRequestOptions } from '@sitecore-jss/sitecore-jss-angular'; +import { + ComponentRendering, + trackingApi, + TrackingRequestOptions, +} from '@sitecore-jss/sitecore-jss-angular'; import { environment } from '../../../environments/environment'; import { JssDataFetcherService } from '../../jss-data-fetcher.service';