Loading src/app/common/services/client-meta.service.ts +13 −1 Original line number Original line Diff line number Diff line Loading @@ -2,6 +2,7 @@ import { Injectable, Injector } from '@angular/core'; import { Location } from '@angular/common'; import { Location } from '@angular/common'; import hashCode from '../../helpers/hash-code'; import hashCode from '../../helpers/hash-code'; import { Session } from '../../services/session'; import { Session } from '../../services/session'; import { Client } from '../../services/api'; let uniqId = 0; let uniqId = 0; Loading @@ -23,7 +24,11 @@ export class ClientMetaService { protected inherited: boolean = false; protected inherited: boolean = false; constructor(protected location: Location, protected session: Session) { constructor( protected location: Location, protected session: Session, protected client: Client ) { this.id = ++uniqId; this.id = ++uniqId; this.timestamp = Date.now(); this.timestamp = Date.now(); Loading Loading @@ -146,6 +151,13 @@ export class ClientMetaService { }; }; } } async recordView(entity) { await this.client.post( 'api/v2/analytics/views/entity/' + entity.guid, this.build() ); } protected checkInheritance() { protected checkInheritance() { if (!this.inherited) { if (!this.inherited) { console.warn( console.warn( Loading src/app/modules/blogs/view/view.ts +13 −11 Original line number Original line Diff line number Diff line Loading @@ -6,6 +6,8 @@ import { OnDestroy, OnDestroy, OnInit, OnInit, ViewChild, ViewChild, Injector, SkipSelf, } from '@angular/core'; } from '@angular/core'; import { Router } from '@angular/router'; import { Router } from '@angular/router'; Loading @@ -22,6 +24,7 @@ import { optimizedResize } from '../../../utils/optimized-resize'; import { OverlayModalService } from '../../../services/ux/overlay-modal'; import { OverlayModalService } from '../../../services/ux/overlay-modal'; import { ActivityService } from '../../../common/services/activity.service'; import { ActivityService } from '../../../common/services/activity.service'; import { ShareModalComponent } from '../../../modules/modals/share/share'; import { ShareModalComponent } from '../../../modules/modals/share/share'; import { ClientMetaService } from '../../../common/services/client-meta.service'; @Component({ @Component({ moduleId: module.id, moduleId: module.id, Loading @@ -30,7 +33,7 @@ import { ShareModalComponent } from '../../../modules/modals/share/share'; class: 'm-blog', class: 'm-blog', }, }, templateUrl: 'view.html', templateUrl: 'view.html', providers: [ActivityService], providers: [ActivityService, ClientMetaService], }) }) export class BlogView implements OnInit, OnDestroy { export class BlogView implements OnInit, OnDestroy { minds; minds; Loading Loading @@ -98,8 +101,15 @@ export class BlogView implements OnInit, OnDestroy { public analyticsService: AnalyticsService, public analyticsService: AnalyticsService, protected activityService: ActivityService, protected activityService: ActivityService, private cd: ChangeDetectorRef, private cd: ChangeDetectorRef, private overlayModal: OverlayModalService private overlayModal: OverlayModalService, private clientMetaService: ClientMetaService, @SkipSelf() injector: Injector ) { ) { this.clientMetaService .inherit(injector) .setSource('single') .setMedium('single'); this.minds = window.Minds; this.minds = window.Minds; this.element = _element.nativeElement; this.element = _element.nativeElement; optimizedResize.add(this.onResize.bind(this)); optimizedResize.add(this.onResize.bind(this)); Loading @@ -108,7 +118,7 @@ export class BlogView implements OnInit, OnDestroy { ngOnInit() { ngOnInit() { this.isVisible(); this.isVisible(); this.context.set('object:blog'); this.context.set('object:blog'); this.recordAnalytics(); this.clientMetaService.recordView(this.blog); } } isVisible() { isVisible() { Loading Loading @@ -219,12 +229,4 @@ export class BlogView implements OnInit, OnDestroy { onResize(event: Event) { onResize(event: Event) { this.calculateLockScreenHeight(); this.calculateLockScreenHeight(); } } recordAnalytics() { this.analyticsService.recordView(this.blog, { position: -1, source: 'single', medium: 'single', }); } } } src/app/modules/channels/channel.component.spec.ts +3 −3 Original line number Original line Diff line number Diff line Loading @@ -37,8 +37,8 @@ import { FeaturesService } from '../../services/features.service'; import { featuresServiceMock } from '../../../tests/features-service-mock.spec'; import { featuresServiceMock } from '../../../tests/features-service-mock.spec'; import { BlockListService } from '../../common/services/block-list.service'; import { BlockListService } from '../../common/services/block-list.service'; import { ChannelMode } from '../../interfaces/entities'; import { ChannelMode } from '../../interfaces/entities'; import { AnalyticsService } from '../../services/analytics'; import { ClientMetaService } from '../../common/services/client-meta.service'; import { analyticsServiceMock } from '../../../tests/analytics-service-mock.spec'; import { clientMetaServiceMock } from '../../../tests/client-meta-service-mock.spec'; describe('ChannelComponent', () => { describe('ChannelComponent', () => { let comp: ChannelComponent; let comp: ChannelComponent; Loading Loading @@ -107,7 +107,7 @@ describe('ChannelComponent', () => { }, }, { provide: FeaturesService, useValue: featuresServiceMock }, { provide: FeaturesService, useValue: featuresServiceMock }, { provide: BlockListService, useValue: MockService(BlockListService) }, { provide: BlockListService, useValue: MockService(BlockListService) }, { provide: AnalyticsService, useValue: analyticsServiceMock }, { provide: ClientMetaService, useValue: clientMetaServiceMock }, ], ], }).compileComponents(); // compile template and css }).compileComponents(); // compile template and css })); })); Loading src/app/modules/channels/channel.component.ts +11 −12 Original line number Original line Diff line number Diff line import { Component, ViewChild } from '@angular/core'; import { Component, ViewChild, SkipSelf, Injector } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router'; import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs'; Loading @@ -18,6 +18,7 @@ import { DialogService } from '../../common/services/confirm-leave-dialog.servic import { BlockListService } from '../../common/services/block-list.service'; import { BlockListService } from '../../common/services/block-list.service'; import { ChannelSortedComponent } from './sorted/sorted.component'; import { ChannelSortedComponent } from './sorted/sorted.component'; import { AnalyticsService } from '../../services/analytics'; import { AnalyticsService } from '../../services/analytics'; import { ClientMetaService } from '../../common/services/client-meta.service'; @Component({ @Component({ moduleId: module.id, moduleId: module.id, Loading Loading @@ -55,8 +56,14 @@ export class ChannelComponent { private context: ContextService, private context: ContextService, private dialogService: DialogService, private dialogService: DialogService, private blockListService: BlockListService, private blockListService: BlockListService, private analyticsService: AnalyticsService private clientMetaService: ClientMetaService, ) {} @SkipSelf() injector: Injector ) { this.clientMetaService .inherit(injector) .setSource('single') .setMedium('single'); } ngOnInit() { ngOnInit() { this.title.setTitle('Channel'); this.title.setTitle('Channel'); Loading Loading @@ -135,7 +142,7 @@ export class ChannelComponent { this.addRecent(); this.addRecent(); } } this.recordAnalytics(); this.clientMetaService.recordView(this.user); }) }) .catch(e => { .catch(e => { if (e.status === 0) { if (e.status === 0) { Loading Loading @@ -239,14 +246,6 @@ export class ChannelComponent { .splice('recent', 50); .splice('recent', 50); } } recordAnalytics() { this.analyticsService.recordView(this.user, { position: -1, source: 'single', medium: 'single', }); } /** /** * canDeactivate() * canDeactivate() * Determines whether a page can be deactivated. * Determines whether a page can be deactivated. Loading src/app/modules/legacy/components/cards/activity/activity-analytics-on-view.service.ts +3 −4 Original line number Original line Diff line number Diff line Loading @@ -61,10 +61,9 @@ export class ActivityAnalyticsOnViewService implements OnDestroy { } } }); }); this.scroll$ = this.scroll.listenForView().subscribe(this.checkVisibility); this.scroll$ = this.scroll.listenForView().subscribe(() => { // Do a check for the initial posts this.checkVisibility(); this.checkVisibility(); }); } } checkVisibility() { checkVisibility() { Loading Loading
src/app/common/services/client-meta.service.ts +13 −1 Original line number Original line Diff line number Diff line Loading @@ -2,6 +2,7 @@ import { Injectable, Injector } from '@angular/core'; import { Location } from '@angular/common'; import { Location } from '@angular/common'; import hashCode from '../../helpers/hash-code'; import hashCode from '../../helpers/hash-code'; import { Session } from '../../services/session'; import { Session } from '../../services/session'; import { Client } from '../../services/api'; let uniqId = 0; let uniqId = 0; Loading @@ -23,7 +24,11 @@ export class ClientMetaService { protected inherited: boolean = false; protected inherited: boolean = false; constructor(protected location: Location, protected session: Session) { constructor( protected location: Location, protected session: Session, protected client: Client ) { this.id = ++uniqId; this.id = ++uniqId; this.timestamp = Date.now(); this.timestamp = Date.now(); Loading Loading @@ -146,6 +151,13 @@ export class ClientMetaService { }; }; } } async recordView(entity) { await this.client.post( 'api/v2/analytics/views/entity/' + entity.guid, this.build() ); } protected checkInheritance() { protected checkInheritance() { if (!this.inherited) { if (!this.inherited) { console.warn( console.warn( Loading
src/app/modules/blogs/view/view.ts +13 −11 Original line number Original line Diff line number Diff line Loading @@ -6,6 +6,8 @@ import { OnDestroy, OnDestroy, OnInit, OnInit, ViewChild, ViewChild, Injector, SkipSelf, } from '@angular/core'; } from '@angular/core'; import { Router } from '@angular/router'; import { Router } from '@angular/router'; Loading @@ -22,6 +24,7 @@ import { optimizedResize } from '../../../utils/optimized-resize'; import { OverlayModalService } from '../../../services/ux/overlay-modal'; import { OverlayModalService } from '../../../services/ux/overlay-modal'; import { ActivityService } from '../../../common/services/activity.service'; import { ActivityService } from '../../../common/services/activity.service'; import { ShareModalComponent } from '../../../modules/modals/share/share'; import { ShareModalComponent } from '../../../modules/modals/share/share'; import { ClientMetaService } from '../../../common/services/client-meta.service'; @Component({ @Component({ moduleId: module.id, moduleId: module.id, Loading @@ -30,7 +33,7 @@ import { ShareModalComponent } from '../../../modules/modals/share/share'; class: 'm-blog', class: 'm-blog', }, }, templateUrl: 'view.html', templateUrl: 'view.html', providers: [ActivityService], providers: [ActivityService, ClientMetaService], }) }) export class BlogView implements OnInit, OnDestroy { export class BlogView implements OnInit, OnDestroy { minds; minds; Loading Loading @@ -98,8 +101,15 @@ export class BlogView implements OnInit, OnDestroy { public analyticsService: AnalyticsService, public analyticsService: AnalyticsService, protected activityService: ActivityService, protected activityService: ActivityService, private cd: ChangeDetectorRef, private cd: ChangeDetectorRef, private overlayModal: OverlayModalService private overlayModal: OverlayModalService, private clientMetaService: ClientMetaService, @SkipSelf() injector: Injector ) { ) { this.clientMetaService .inherit(injector) .setSource('single') .setMedium('single'); this.minds = window.Minds; this.minds = window.Minds; this.element = _element.nativeElement; this.element = _element.nativeElement; optimizedResize.add(this.onResize.bind(this)); optimizedResize.add(this.onResize.bind(this)); Loading @@ -108,7 +118,7 @@ export class BlogView implements OnInit, OnDestroy { ngOnInit() { ngOnInit() { this.isVisible(); this.isVisible(); this.context.set('object:blog'); this.context.set('object:blog'); this.recordAnalytics(); this.clientMetaService.recordView(this.blog); } } isVisible() { isVisible() { Loading Loading @@ -219,12 +229,4 @@ export class BlogView implements OnInit, OnDestroy { onResize(event: Event) { onResize(event: Event) { this.calculateLockScreenHeight(); this.calculateLockScreenHeight(); } } recordAnalytics() { this.analyticsService.recordView(this.blog, { position: -1, source: 'single', medium: 'single', }); } } }
src/app/modules/channels/channel.component.spec.ts +3 −3 Original line number Original line Diff line number Diff line Loading @@ -37,8 +37,8 @@ import { FeaturesService } from '../../services/features.service'; import { featuresServiceMock } from '../../../tests/features-service-mock.spec'; import { featuresServiceMock } from '../../../tests/features-service-mock.spec'; import { BlockListService } from '../../common/services/block-list.service'; import { BlockListService } from '../../common/services/block-list.service'; import { ChannelMode } from '../../interfaces/entities'; import { ChannelMode } from '../../interfaces/entities'; import { AnalyticsService } from '../../services/analytics'; import { ClientMetaService } from '../../common/services/client-meta.service'; import { analyticsServiceMock } from '../../../tests/analytics-service-mock.spec'; import { clientMetaServiceMock } from '../../../tests/client-meta-service-mock.spec'; describe('ChannelComponent', () => { describe('ChannelComponent', () => { let comp: ChannelComponent; let comp: ChannelComponent; Loading Loading @@ -107,7 +107,7 @@ describe('ChannelComponent', () => { }, }, { provide: FeaturesService, useValue: featuresServiceMock }, { provide: FeaturesService, useValue: featuresServiceMock }, { provide: BlockListService, useValue: MockService(BlockListService) }, { provide: BlockListService, useValue: MockService(BlockListService) }, { provide: AnalyticsService, useValue: analyticsServiceMock }, { provide: ClientMetaService, useValue: clientMetaServiceMock }, ], ], }).compileComponents(); // compile template and css }).compileComponents(); // compile template and css })); })); Loading
src/app/modules/channels/channel.component.ts +11 −12 Original line number Original line Diff line number Diff line import { Component, ViewChild } from '@angular/core'; import { Component, ViewChild, SkipSelf, Injector } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router'; import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs'; Loading @@ -18,6 +18,7 @@ import { DialogService } from '../../common/services/confirm-leave-dialog.servic import { BlockListService } from '../../common/services/block-list.service'; import { BlockListService } from '../../common/services/block-list.service'; import { ChannelSortedComponent } from './sorted/sorted.component'; import { ChannelSortedComponent } from './sorted/sorted.component'; import { AnalyticsService } from '../../services/analytics'; import { AnalyticsService } from '../../services/analytics'; import { ClientMetaService } from '../../common/services/client-meta.service'; @Component({ @Component({ moduleId: module.id, moduleId: module.id, Loading Loading @@ -55,8 +56,14 @@ export class ChannelComponent { private context: ContextService, private context: ContextService, private dialogService: DialogService, private dialogService: DialogService, private blockListService: BlockListService, private blockListService: BlockListService, private analyticsService: AnalyticsService private clientMetaService: ClientMetaService, ) {} @SkipSelf() injector: Injector ) { this.clientMetaService .inherit(injector) .setSource('single') .setMedium('single'); } ngOnInit() { ngOnInit() { this.title.setTitle('Channel'); this.title.setTitle('Channel'); Loading Loading @@ -135,7 +142,7 @@ export class ChannelComponent { this.addRecent(); this.addRecent(); } } this.recordAnalytics(); this.clientMetaService.recordView(this.user); }) }) .catch(e => { .catch(e => { if (e.status === 0) { if (e.status === 0) { Loading Loading @@ -239,14 +246,6 @@ export class ChannelComponent { .splice('recent', 50); .splice('recent', 50); } } recordAnalytics() { this.analyticsService.recordView(this.user, { position: -1, source: 'single', medium: 'single', }); } /** /** * canDeactivate() * canDeactivate() * Determines whether a page can be deactivated. * Determines whether a page can be deactivated. Loading
src/app/modules/legacy/components/cards/activity/activity-analytics-on-view.service.ts +3 −4 Original line number Original line Diff line number Diff line Loading @@ -61,10 +61,9 @@ export class ActivityAnalyticsOnViewService implements OnDestroy { } } }); }); this.scroll$ = this.scroll.listenForView().subscribe(this.checkVisibility); this.scroll$ = this.scroll.listenForView().subscribe(() => { // Do a check for the initial posts this.checkVisibility(); this.checkVisibility(); }); } } checkVisibility() { checkVisibility() { Loading