@@ -14,10 +14,8 @@ import { Metric } from '../../../core/shared/metric.model';
1414import { BaseMetricComponent } from './base-metric.component' ;
1515import { MetricLoaderService } from './metric-loader.service' ;
1616import { hasValue } from '../../empty.util' ;
17- import { BrowserKlaroService , CookieConsents } from '../../cookies/browser-klaro.service' ;
18- import { KlaroService } from '../../cookies/klaro.service' ;
19- import { startWith } from 'rxjs/operators' ;
20- import { environment } from '../../../../environments/environment' ;
17+ import { CookieConsents , KlaroService } from '../../cookies/klaro.service' ;
18+ import { startWith } from 'rxjs/operators' ;
2119
2220@Component ( {
2321 // eslint-disable-next-line @angular-eslint/component-selector
@@ -49,9 +47,7 @@ export class MetricLoaderComponent implements OnInit, OnDestroy {
4947
5048 settingsSubscription : Subscription ;
5149
52- private thirdPartyMetrics = environment . metricsConsents . filter ( metric => metric . enabled ) . map ( metric => metric . key ) ;
53-
54- private browserKlaroService : BrowserKlaroService ;
50+ private thirdPartyMetrics = [ 'plumX' , 'altmetric' , 'dimensions' ] ;
5551
5652 private hasLoadedScript : boolean ;
5753
@@ -60,13 +56,12 @@ export class MetricLoaderComponent implements OnInit, OnDestroy {
6056 private metricLoaderService : MetricLoaderService ,
6157 private klaroService : KlaroService ,
6258 ) {
63- this . browserKlaroService = ( this . klaroService as BrowserKlaroService ) ;
64- this . browserKlaroService . watchConsentUpdates ( ) ;
65- this . consentUpdates$ = this . browserKlaroService . consentsUpdates$ ;
59+ this . klaroService . watchConsentUpdates ( ) ;
60+ this . consentUpdates$ = this . klaroService . consentsUpdates$ ;
6661 }
6762
6863 ngOnInit ( ) {
69- this . cookiesSubscription = this . browserKlaroService . getSavedPreferences ( ) . subscribe ( ( consents ) => {
64+ this . cookiesSubscription = this . klaroService . getSavedPreferences ( ) . subscribe ( ( consents ) => {
7065 this . loadComponent ( this . metric , this . getCanLoadScript ( consents ) ) ;
7166 } ) ;
7267 }
@@ -77,10 +72,6 @@ export class MetricLoaderComponent implements OnInit, OnDestroy {
7772 }
7873 this . hasLoadedScript = ! ! canLoadScript ;
7974 this . metricLoaderService . loadMetricTypeComponent ( metric . metricType , canLoadScript ) . then ( ( component ) => {
80- if ( hasValue ( this . cookiesSubscription ) && canLoadScript ) {
81- this . container . clear ( ) ;
82- this . cookiesSubscription . unsubscribe ( ) ;
83- }
8475 this . instantiateComponent ( component , metric , canLoadScript , forceRendering ) ;
8576 } ) ;
8677 }
@@ -97,6 +88,8 @@ export class MetricLoaderComponent implements OnInit, OnDestroy {
9788 instantiateComponent ( component : any , metric : Metric , canLoadScript : boolean , forceRendering ?: boolean ) {
9889 const factory = this . componentFactoryResolver . resolveComponentFactory ( component ) ;
9990 this . componentType = component ;
91+ this . container . clear ( ) ;
92+
10093 const ref = this . container . createComponent ( factory ) ;
10194 const componentInstance = ref . instance as BaseMetricComponent ;
10295 componentInstance . metric = metric ;
@@ -134,14 +127,18 @@ export class MetricLoaderComponent implements OnInit, OnDestroy {
134127 * @private
135128 */
136129 private reloadComponentOnConsentsChange ( componentInstance : BaseMetricComponent , canLoadScript : boolean ) : void {
130+ if ( hasValue ( this . settingsSubscription ) ) {
131+ return ;
132+ }
133+
137134 this . settingsSubscription = combineLatest ( [
138135 this . consentUpdates$ ,
139136 componentInstance . requestSettingsConsent . pipe ( startWith ( undefined ) )
140137 ] ) . subscribe ( ( [ consents , request ] ) => {
141138 canLoadScript = this . getCanLoadScript ( consents ) ;
142139
143140 if ( request && ! canLoadScript ) {
144- this . browserKlaroService . showSettings ( ) ;
141+ this . klaroService . showSettings ( ) ;
145142 }
146143
147144 if ( canLoadScript && ! this . hasLoadedScript ) {
0 commit comments