1 | "use strict";
|
---|
2 | /**
|
---|
3 | * @license
|
---|
4 | * Copyright Google LLC All Rights Reserved.
|
---|
5 | *
|
---|
6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
7 | * found in the LICENSE file at https://angular.io/license
|
---|
8 | */
|
---|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
10 | exports.AnalyticsReporter = exports.ForwardingAnalytics = exports.AnalyticsReportKind = void 0;
|
---|
11 | var AnalyticsReportKind;
|
---|
12 | (function (AnalyticsReportKind) {
|
---|
13 | AnalyticsReportKind["Event"] = "event";
|
---|
14 | AnalyticsReportKind["Screenview"] = "screenview";
|
---|
15 | AnalyticsReportKind["Pageview"] = "pageview";
|
---|
16 | AnalyticsReportKind["Timing"] = "timing";
|
---|
17 | })(AnalyticsReportKind = exports.AnalyticsReportKind || (exports.AnalyticsReportKind = {}));
|
---|
18 | /**
|
---|
19 | * A class that follows the Analytics interface and forwards analytic reports (JavaScript objects).
|
---|
20 | * AnalyticsReporter is the counterpart which takes analytic reports and report them to another
|
---|
21 | * Analytics interface.
|
---|
22 | */
|
---|
23 | class ForwardingAnalytics {
|
---|
24 | constructor(_fn) {
|
---|
25 | this._fn = _fn;
|
---|
26 | }
|
---|
27 | event(category, action, options) {
|
---|
28 | this._fn({
|
---|
29 | kind: AnalyticsReportKind.Event,
|
---|
30 | category,
|
---|
31 | action,
|
---|
32 | options: { ...options },
|
---|
33 | });
|
---|
34 | }
|
---|
35 | screenview(screenName, appName, options) {
|
---|
36 | this._fn({
|
---|
37 | kind: AnalyticsReportKind.Screenview,
|
---|
38 | screenName,
|
---|
39 | appName,
|
---|
40 | options: { ...options },
|
---|
41 | });
|
---|
42 | }
|
---|
43 | pageview(path, options) {
|
---|
44 | this._fn({
|
---|
45 | kind: AnalyticsReportKind.Pageview,
|
---|
46 | path,
|
---|
47 | options: { ...options },
|
---|
48 | });
|
---|
49 | }
|
---|
50 | timing(category, variable, time, options) {
|
---|
51 | this._fn({
|
---|
52 | kind: AnalyticsReportKind.Timing,
|
---|
53 | category,
|
---|
54 | variable,
|
---|
55 | time,
|
---|
56 | options: { ...options },
|
---|
57 | });
|
---|
58 | }
|
---|
59 | // We do not support flushing.
|
---|
60 | flush() {
|
---|
61 | return Promise.resolve();
|
---|
62 | }
|
---|
63 | }
|
---|
64 | exports.ForwardingAnalytics = ForwardingAnalytics;
|
---|
65 | class AnalyticsReporter {
|
---|
66 | constructor(_analytics) {
|
---|
67 | this._analytics = _analytics;
|
---|
68 | }
|
---|
69 | report(report) {
|
---|
70 | switch (report.kind) {
|
---|
71 | case AnalyticsReportKind.Event:
|
---|
72 | this._analytics.event(report.category, report.action, report.options);
|
---|
73 | break;
|
---|
74 | case AnalyticsReportKind.Screenview:
|
---|
75 | this._analytics.screenview(report.screenName, report.appName, report.options);
|
---|
76 | break;
|
---|
77 | case AnalyticsReportKind.Pageview:
|
---|
78 | this._analytics.pageview(report.path, report.options);
|
---|
79 | break;
|
---|
80 | case AnalyticsReportKind.Timing:
|
---|
81 | this._analytics.timing(report.category, report.variable, report.time, report.options);
|
---|
82 | break;
|
---|
83 | default:
|
---|
84 | throw new Error('Unexpected analytics report: ' + JSON.stringify(report));
|
---|
85 | }
|
---|
86 | }
|
---|
87 | }
|
---|
88 | exports.AnalyticsReporter = AnalyticsReporter;
|
---|