src/lib/telemetry-utils.service.ts
Properties |
Methods |
constructor(discussionEvents: DiscussionEventsService, router: Router)
|
|||||||||
Defined in src/lib/telemetry-utils.service.ts:20
|
|||||||||
Parameters :
|
deleteContext | ||||
deleteContext(prevTopic)
|
||||
Defined in src/lib/telemetry-utils.service.ts:40
|
||||
Parameters :
Returns :
void
|
getContext |
getContext()
|
Defined in src/lib/telemetry-utils.service.ts:47
|
Returns :
{}
|
getRollUp |
getRollUp()
|
Defined in src/lib/telemetry-utils.service.ts:100
|
Returns :
{}
|
logImpression | ||||
logImpression(pageId)
|
||||
Defined in src/lib/telemetry-utils.service.ts:51
|
||||
Parameters :
Returns :
void
|
logInteract | ||||||
logInteract(event, pageId)
|
||||||
Defined in src/lib/telemetry-utils.service.ts:70
|
||||||
Parameters :
Returns :
void
|
setContext | ||||
setContext(context)
|
||||
Defined in src/lib/telemetry-utils.service.ts:27
|
||||
Parameters :
Returns :
void
|
uppendContext | ||||
uppendContext(data)
|
||||
Defined in src/lib/telemetry-utils.service.ts:32
|
||||
Parameters :
Returns :
void
|
_context |
Type : []
|
Default value : []
|
Defined in src/lib/telemetry-utils.service.ts:19
|
currentObj |
Type : object
|
Default value : {}
|
Defined in src/lib/telemetry-utils.service.ts:20
|
import { DiscussionEventsService } from './discussion-events.service';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
/* tslint:disable */
import * as _ from 'lodash'
/* tslint:enable */
interface ITelemetryObj {
eid: string,
edata: {},
context?: {}
}
@Injectable({
providedIn: 'root'
})
export class TelemetryUtilsService {
_context = []
currentObj = {};
constructor(
private discussionEvents: DiscussionEventsService,
private router: Router
) { }
setContext(context) {
this._context = context;
this.currentObj = _.last(context);
}
uppendContext(data) {
const matchedC = _.find(this._context, { id: data.id });
if (!_.isEmpty(data) && !_.isEqual(data, matchedC)) {
this._context.push(data);
}
this.currentObj = _.last(this._context);
}
deleteContext(prevTopic) {
const topic = _.find(this._context, prevTopic);
if (topic) {
this._context = _.reject(this._context, topic);
}
}
getContext() {
return this._context;
}
logImpression(pageId) {
this.discussionEvents.emitTelemetry({});
const impressionEvent: ITelemetryObj = {
eid: 'IMPRESSION',
edata: {
type: 'view',
pageid: pageId,
uri: this.router.url
}
}
if (this.currentObj) {
impressionEvent.context = { cdata: [{
id: _.get(this.currentObj, 'id').toString(),
type: _.get(this.currentObj, 'type') }
]};
}
this.discussionEvents.emitTelemetry(impressionEvent);
}
logInteract(event, pageId) {
const target = _.get(event, 'currentTarget.attributes.id') || _.get(event, 'target.attributes.id') ||
_.get(event, 'srcElement.attributes.id');
const interactEvent: ITelemetryObj = {
eid: 'INTERACT',
edata: {
id: _.get(target, 'value') || _.get(event, 'action'),
type: 'CLICK',
pageid: pageId
}
};
if (this.currentObj) {
const object = {
id: _.get(this.currentObj, 'id').toString(),
type: _.get(this.currentObj, 'type'),
ver: '1'
};
object['rollup'] = this._context.length > 1 ? this.getRollUp() : {};
interactEvent.context = {
cdata: [{
id: _.get(this.currentObj, 'id').toString(),
type: _.get(this.currentObj, 'type')
}], object
};
}
this.discussionEvents.emitTelemetry(interactEvent);
}
getRollUp() {
const rollUp = {};
const data = _.reject(this._context, this.currentObj);
if (this._context.length > 1) {
data.forEach((element, index) => {
console.log('rollup', element);
rollUp['l' + (index + 1)] = element.toString();
});
}
if (_.get(this.currentObj, 'type') !== 'Post') {
return rollUp;
}
return {};
}
}