Commit c3315ec2 authored by Mark Harding's avatar Mark Harding

(feat): move entire process to clientMetaService function

No related merge requests found
Pipeline #85174547 passed with stages
in 49 minutes and 30 seconds
......@@ -2,6 +2,7 @@ import { Injectable, Injector } from '@angular/core';
import { Location } from '@angular/common';
import hashCode from '../../helpers/hash-code';
import { Session } from '../../services/session';
import { Client } from '../../services/api';
let uniqId = 0;
......@@ -23,7 +24,11 @@ export class ClientMetaService {
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.timestamp = Date.now();
......@@ -146,6 +151,12 @@ export class ClientMetaService {
};
}
async recordView(entity) {
await this.client.post('api/v2/analytics/views/entity/' + entity.guid, {
client_meta: this.build(),
});
}
protected checkInheritance() {
if (!this.inherited) {
console.warn(
......
......@@ -6,6 +6,8 @@ import {
OnDestroy,
OnInit,
ViewChild,
Injector,
SkipSelf,
} from '@angular/core';
import { Router } from '@angular/router';
......@@ -22,6 +24,7 @@ import { optimizedResize } from '../../../utils/optimized-resize';
import { OverlayModalService } from '../../../services/ux/overlay-modal';
import { ActivityService } from '../../../common/services/activity.service';
import { ShareModalComponent } from '../../../modules/modals/share/share';
import { ClientMetaService } from '../../../common/services/client-meta.service';
@Component({
moduleId: module.id,
......@@ -30,7 +33,7 @@ import { ShareModalComponent } from '../../../modules/modals/share/share';
class: 'm-blog',
},
templateUrl: 'view.html',
providers: [ActivityService],
providers: [ActivityService, ClientMetaService],
})
export class BlogView implements OnInit, OnDestroy {
minds;
......@@ -98,8 +101,15 @@ export class BlogView implements OnInit, OnDestroy {
public analyticsService: AnalyticsService,
protected activityService: ActivityService,
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.element = _element.nativeElement;
optimizedResize.add(this.onResize.bind(this));
......@@ -108,7 +118,7 @@ export class BlogView implements OnInit, OnDestroy {
ngOnInit() {
this.isVisible();
this.context.set('object:blog');
this.recordAnalytics();
this.clientMetaService.recordView(this.blog);
}
isVisible() {
......@@ -219,12 +229,4 @@ export class BlogView implements OnInit, OnDestroy {
onResize(event: Event) {
this.calculateLockScreenHeight();
}
recordAnalytics() {
this.analyticsService.recordView(this.blog, {
position: -1,
source: 'single',
medium: 'single',
});
}
}
......@@ -37,8 +37,8 @@ import { FeaturesService } from '../../services/features.service';
import { featuresServiceMock } from '../../../tests/features-service-mock.spec';
import { BlockListService } from '../../common/services/block-list.service';
import { ChannelMode } from '../../interfaces/entities';
import { AnalyticsService } from '../../services/analytics';
import { analyticsServiceMock } from '../../../tests/analytics-service-mock.spec';
import { ClientMetaService } from '../../common/services/client-meta.service';
import { clientMetaServiceMock } from '../../../tests/client-meta-service-mock.spec';
describe('ChannelComponent', () => {
let comp: ChannelComponent;
......@@ -107,7 +107,7 @@ describe('ChannelComponent', () => {
},
{ provide: FeaturesService, useValue: featuresServiceMock },
{ provide: BlockListService, useValue: MockService(BlockListService) },
{ provide: AnalyticsService, useValue: analyticsServiceMock },
{ provide: ClientMetaService, useValue: clientMetaServiceMock },
],
}).compileComponents(); // compile template and css
}));
......
import { Component, ViewChild } from '@angular/core';
import { Component, ViewChild, SkipSelf, Injector } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from 'rxjs';
......@@ -17,12 +17,13 @@ import { Observable } from 'rxjs';
import { DialogService } from '../../common/services/confirm-leave-dialog.service';
import { BlockListService } from '../../common/services/block-list.service';
import { ChannelSortedComponent } from './sorted/sorted.component';
import { AnalyticsService } from '../../services/analytics';
import { ClientMetaService } from '../../common/services/client-meta.service';
@Component({
moduleId: module.id,
selector: 'm-channel',
templateUrl: 'channel.component.html',
providers: [ClientMetaService],
})
export class ChannelComponent {
minds = window.Minds;
......@@ -55,8 +56,14 @@ export class ChannelComponent {
private context: ContextService,
private dialogService: DialogService,
private blockListService: BlockListService,
private analyticsService: AnalyticsService
) {}
private clientMetaService: ClientMetaService,
@SkipSelf() injector: Injector
) {
this.clientMetaService
.inherit(injector)
.setSource('single')
.setMedium('single');
}
ngOnInit() {
this.title.setTitle('Channel');
......@@ -135,7 +142,7 @@ export class ChannelComponent {
this.addRecent();
}
this.recordAnalytics();
this.clientMetaService.recordView(this.user);
})
.catch(e => {
if (e.status === 0) {
......@@ -239,14 +246,6 @@ export class ChannelComponent {
.splice('recent', 50);
}
recordAnalytics() {
this.analyticsService.recordView(this.user, {
position: -1,
source: 'single',
medium: 'single',
});
}
/**
* canDeactivate()
* Determines whether a page can be deactivated.
......
......@@ -61,10 +61,9 @@ export class ActivityAnalyticsOnViewService implements OnDestroy {
}
});
this.scroll$ = this.scroll.listenForView().subscribe(this.checkVisibility);
// Do a check for the initial posts
this.checkVisibility();
this.scroll$ = this.scroll.listenForView().subscribe(() => {
this.checkVisibility();
});
}
checkVisibility() {
......
......@@ -239,6 +239,8 @@ export class Activity implements OnInit {
this.activity.time_created || Math.floor(Date.now() / 1000);
this.allowComments = this.activity.allow_comments;
this.activityAnalyticsOnViewService.checkVisibility(); // perform check
}
getOwnerIconTime() {
......
......@@ -5,6 +5,8 @@ import {
OnDestroy,
OnInit,
ViewChild,
SkipSelf,
Injector,
} from '@angular/core';
import { Location } from '@angular/common';
import { Event, NavigationStart, Router } from '@angular/router';
......@@ -23,6 +25,7 @@ import { MindsVideoComponent } from '../components/video/video.component';
import isMobileOrTablet from '../../../helpers/is-mobile-or-tablet';
import { ActivityService } from '../../../common/services/activity.service';
import { SiteService } from '../../../common/services/site.service';
import { ClientMetaService } from '../../../common/services/client-meta.service';
export type MediaModalParams = {
redirectUrl?: string;
......@@ -58,7 +61,7 @@ export type MediaModalParams = {
transition(':leave', [animate('300ms', style({ opacity: 0 }))]),
]),
],
providers: [ActivityService],
providers: [ActivityService, ClientMetaService],
})
export class MediaModalComponent implements OnInit, OnDestroy {
minds = window.Minds;
......@@ -120,8 +123,15 @@ export class MediaModalComponent implements OnInit, OnDestroy {
private overlayModal: OverlayModalService,
private router: Router,
private location: Location,
private site: SiteService
) {}
private site: SiteService,
private clientMetaService: ClientMetaService,
@SkipSelf() injector: Injector
) {
this.clientMetaService
.inherit(injector)
.setSource('single')
.setMedium('modal');
}
ngOnInit() {
// Prevent dismissal of modal when it's just been opened
......@@ -212,7 +222,7 @@ export class MediaModalComponent implements OnInit, OnDestroy {
url = `/pro/${this.site.pro.user_guid}${url}`;
}
this.recordAnalytics();
this.clientMetaService.recordView(this.entity);
this.analyticsService.send('pageview', {
url,
});
......@@ -564,12 +574,4 @@ export class MediaModalComponent implements OnInit, OnDestroy {
this.location.replaceState(this.entity.modal_source_url);
}
}
recordAnalytics() {
this.analyticsService.recordView(this.entity, {
position: -1,
source: 'single',
medium: 'modal',
});
}
}
import { ChangeDetectorRef, Component, OnInit, OnDestroy } from '@angular/core';
import {
ChangeDetectorRef,
Component,
OnInit,
OnDestroy,
SkipSelf,
Injector,
} from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from 'rxjs';
......@@ -12,6 +19,7 @@ import { ContextService } from '../../../services/context.service';
import { MindsTitle } from '../../../services/ux/title';
import { ActivityService } from '../../../common/services/activity.service';
import { AnalyticsService } from '../../../services/analytics';
import { ClientMetaService } from '../../../common/services/client-meta.service';
@Component({
moduleId: module.id,
......@@ -24,6 +32,7 @@ import { AnalyticsService } from '../../../services/analytics';
deps: [Client],
},
ActivityService,
ClientMetaService,
],
})
export class MediaViewComponent implements OnInit, OnDestroy {
......@@ -65,8 +74,14 @@ export class MediaViewComponent implements OnInit, OnDestroy {
public context: ContextService,
private cd: ChangeDetectorRef,
protected activityService: ActivityService,
private analyticsService: AnalyticsService
) {}
private clientMetaService: ClientMetaService,
@SkipSelf() injector: Injector
) {
this.clientMetaService
.inherit(injector)
.setSource('single')
.setMedium('single');
}
ngOnInit() {
this.title.setTitle('');
......@@ -86,12 +101,6 @@ export class MediaViewComponent implements OnInit, OnDestroy {
}
}
);
this.analyticsService.recordView(this.entity, {
position: -1,
source: 'single',
medium: 'single',
});
}
ngOnDestroy() {
......@@ -133,6 +142,8 @@ export class MediaViewComponent implements OnInit, OnDestroy {
}
}
this.clientMetaService.recordView(this.entity);
this.detectChanges();
})
.catch(e => {
......
......@@ -63,16 +63,4 @@ export class AnalyticsService {
wasDefaultPrevented() {
return this.defaultPrevented;
}
async recordView(
entity,
meta: {
campaign?: string;
position?: number;
source: string;
medium: string;
}
) {
await this.client.post('api/v2/analytics/entity/' + entity.guid, meta);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment