Skip to content

Commit

Permalink
fix gtag
Browse files Browse the repository at this point in the history
  • Loading branch information
baev committed Jun 15, 2023
1 parent 5cf4815 commit 4ddfc54
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 28 deletions.
3 changes: 2 additions & 1 deletion allure-generator/src/main/javascript/behaviors/GaBehavior.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Behavior } from "backbone.marionette";
import { on } from "../decorators";
import gtag from "../utils/gtag";

export default class GaBehavior extends Behavior {
initialize() {}
Expand All @@ -21,6 +22,6 @@ export default class GaBehavior extends Behavior {
return { [gaKey]: value };
})
.reduce((a, b) => Object.assign(a, b), {});
window.dataLayer.push({ ...eventParams, event });
gtag({ ...eventParams, event });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ class PieChartView extends BaseChartView {
this.statistic = this.model.get("statistic");
const { total } = this.statistic;
const stats = omit(this.statistic, "total");
this.data = Object.keys(stats).map((key) => ({
name: key.toUpperCase(),
value: stats[key],
part: stats[key] / total,
})).filter(item => item.value);
this.data = Object.keys(stats)
.map((key) => ({
name: key.toUpperCase(),
value: stats[key],
part: stats[key] / total,
}))
.filter((item) => item.value);
}

setupViewport() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "./styles.scss";
import PopoverView from "app/components/popover/PopoverView";
import { className, on } from "app/decorators";
import gtag from "app/utils/gtag";
import settings from "app/utils/settings";
import i18next, { LANGUAGES } from "app/utils/translation";
import $ from "jquery";
Expand Down Expand Up @@ -34,7 +35,7 @@ class LanguageSelectView extends PopoverView {
const langId = this.$(e.currentTarget).data("id");
settings.setLanguage(langId);
i18next.changeLanguage(langId);
window.dataLayer.push({ event: "language_change", language: langId });
gtag({ event: "language_change", language: langId });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "./styles.scss";
import { View } from "backbone.marionette";
import { className, on } from "../../decorators";
import translate from "../../helpers/t";
import gtag from "../../utils/gtag";
import { values } from "../../utils/marks";
import template from "./MarksToggleView.hbs";

Expand Down Expand Up @@ -33,7 +34,7 @@ class MarksToggleView extends View {
const checked = el.hasClass("n-label-mark");
const marks = this.settings.getVisibleMarks();
this.settings.setVisibleMarks(Object.assign({}, marks, { [name]: checked }));
window.dataLayer.push({ event: "marks_toggle_click", status: name, checked });
gtag({ event: "marks_toggle_click", status: name, checked });
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "./styles.scss";
import { View } from "backbone.marionette";
import { className, on } from "../../decorators";
import gtag from "../../utils/gtag";
import template from "./NodeSearchView.hbs";

export const SEARCH_QUERY_KEY = "searchQuery";
Expand All @@ -20,7 +21,7 @@ class NodeSearchView extends View {
@on("input input")
onChangeSorting(e) {
this.state.set(SEARCH_QUERY_KEY, e.target.value);
window.dataLayer.push({event: "search"});
gtag({ event: "search" });
}

close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "./styles.scss";
import { View } from "backbone.marionette";
import split from "split.js";
import { className, regions } from "../../decorators";
import gtag from "../../utils/gtag";
import settings from "../../utils/settings";
import template from "./SideBySideView.hbs";

Expand All @@ -18,9 +19,9 @@ class SideBySideView extends View {
gutterSize: 7,
sizes: settings.getSideBySidePosition(),
onDragEnd: function() {
const sizes = splitter.getSizes();
settings.setSideBySidePosition(sizes);
window.dataLayer.push({ event: "side-by-side-resize", sizes });
const sizes = splitter.getSizes();
settings.setSideBySidePosition(sizes);
gtag({ event: "side-by-side-resize", sizes });
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class StatusToggleView extends View {
const checked = el.hasClass("n-label");
const statuses = this.settings.getVisibleStatuses();
this.settings.setVisibleStatuses(Object.assign({}, statuses, { [name]: checked }));
window.dataLayer.push({ event: "status_toggle_click", status: name, checked });
gtag({ event: "status_toggle_click", status: name, checked });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@ import $ from "jquery";
import { defaults } from "underscore";

export const POSITION = {
"top": function({ top, left, width }, { offset }, tipSize) {
top: function({ top, left, width }, { offset }, tipSize) {
return {
top: top - tipSize.height - offset,
left: left + width / 2 - tipSize.width / 2,
};
},

"center": function({ top, left, height, width }, offsets, tipSize) {
center: function({ top, left, height, width }, offsets, tipSize) {
return {
top: top + height / 2,
left: left + width / 2 - tipSize.width / 2,
};
},
"right": function({ top, left, height, width }, { offset }, tipSize) {
right: function({ top, left, height, width }, { offset }, tipSize) {
return {
top: top + height / 2 - tipSize.height / 2,
left: left + width + offset,
};
},
"left": function({ top, left, height }, { offset }, tipSize) {
left: function({ top, left, height }, { offset }, tipSize) {
return {
top: top + height / 2 - tipSize.height / 2,
left: left - offset - tipSize.width,
};
},
"bottom": function({ top, left, height, width }, { offset }, tipSize) {
bottom: function({ top, left, height, width }, { offset }, tipSize) {
return {
top: top + height + offset,
left: left + width / 2 - tipSize.width / 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "./styles.scss";
import { Model } from "backbone";
import { View } from "backbone.marionette";
import { behavior, className, on, regions } from "../../decorators";
import gtag from "../../utils/gtag";
import { getSettingsForTreePlugin } from "../../utils/settingsFactory";
import MarksToggleView from "../marks-toggle/MarksToggleView";
import NodeSearchView from "../node-search/NodeSearchView";
Expand Down Expand Up @@ -43,7 +44,7 @@ class TreeViewContainer extends View {
onInfoClick() {
const show = this.settings.isShowGroupInfo();
this.settings.setShowGroupInfo(!show);
window.dataLayer.push({event: "tree_info_click", enable: !show});
gtag({ event: "tree_info_click", enable: !show });
}

onRender() {
Expand Down
10 changes: 5 additions & 5 deletions allure-generator/src/main/javascript/data/tree/filter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {values as marksValues} from "../../utils/marks";
import { values as marksValues } from "../../utils/marks";

function byStatuses(statuses) {
return (child) => {
Expand Down Expand Up @@ -41,7 +41,9 @@ function byTags(tag) {
tag = (tag && tag.toLowerCase().trim()) || "";
const tags = tag.split(/\s*,\s*/).filter((t) => t);
return (child) => {
const childTags = Array.isArray(child.tags) ? child.tags.filter(t => t).map(t => t.toLowerCase().trim()) : [];
const childTags = Array.isArray(child.tags)
? child.tags.filter((t) => t).map((t) => t.toLowerCase().trim())
: [];
return (
!tag ||
tags.every((t) => childTags.indexOf(t) > -1) ||
Expand All @@ -55,9 +57,7 @@ function byMark(marks) {
if (child.children) {
return child.children.length > 0;
}
return marksValues
.map(k => !marks[k] || child[k])
.reduce((a, b) => a && b, true);
return marksValues.map((k) => !marks[k] || child[k]).reduce((a, b) => a && b, true);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "./styles.scss";
import { View } from "backbone.marionette";
import ErrorSplashView from "../../components/error-splash/ErrorSplashView";
import SideNav from "../../components/side-nav/SideNavView";
import {behavior, className, regions} from "../../decorators";
import { behavior, className, regions } from "../../decorators";
import translate from "../../helpers/t";
import template from "./AppLayout.hbs";

Expand Down
4 changes: 4 additions & 0 deletions allure-generator/src/main/javascript/utils/gtag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default function gtag() {
window.dataLayer = Array.isArray(window.dataLayer) ? window.dataLayer : [];
window.dataLayer.push(arguments);
}
4 changes: 2 additions & 2 deletions allure-generator/src/main/javascript/utils/settingsFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const treePluginDefaults = {
newFailed: false,
newPassed: false,
newBroken: false,
retriesStatusChange : false,
retriesStatusChange: false,
},
showGroupInfo: false,
treeSorting: {
Expand Down Expand Up @@ -151,5 +151,5 @@ export {
getGlobalSettings,
getSettingsForPlugin,
getSettingsForTreePlugin,
getSettingsForWidgetGridPlugin
getSettingsForWidgetGridPlugin,
};
3 changes: 2 additions & 1 deletion allure-generator/src/main/javascript/utils/translation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import i18next from "i18next";
import gtag from "./gtag";
import settings from "./settings";

export const LANGUAGES = [
Expand Down Expand Up @@ -34,7 +35,7 @@ export function initTranslations() {
},
(err) => (err ? reject(err) : resolve()),
);
window.dataLayer.push({ event: "init_language", language: language || "en" });
gtag({ event: "init_language", language: language || "en" });
});
}

Expand Down

0 comments on commit 4ddfc54

Please sign in to comment.