From 9695d22bb9c302a9550a585c59ce039148600d26 Mon Sep 17 00:00:00 2001 From: Matteo Gabriele Date: Tue, 16 Jun 2020 22:55:23 +0200 Subject: [PATCH] fix: no data reporting (#145) add config at start and config at pageview instead of page_view event closes #144 closes #143 --- __tests__/api/pageview.spec.js | 8 ++++---- __tests__/bootstrap.spec.js | 1 + src/api/pageview.js | 4 ++-- src/bootstrap.js | 7 +++++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/__tests__/api/pageview.spec.js b/__tests__/api/pageview.spec.js index 7dbf556..6eca2f1 100644 --- a/__tests__/api/pageview.spec.js +++ b/__tests__/api/pageview.spec.js @@ -1,17 +1,17 @@ import pageview from "@/api/pageview"; -import event from "@/api/event"; +import config from "@/api/config"; -jest.mock("@/api/event"); +jest.mock("@/api/config"); describe("api/pageview", () => { it("should be called with this parameters", () => { pageview("foo"); - expect(event).toHaveBeenCalledWith("page_view", { + expect(config).toHaveBeenCalledWith({ page_path: "foo", page_location: "http://localhost/" }); pageview({ foo: "bar" }); - expect(event).toHaveBeenCalledWith("page_view", { foo: "bar" }); + expect(config).toHaveBeenCalledWith({ foo: "bar" }); }); }); diff --git a/__tests__/bootstrap.spec.js b/__tests__/bootstrap.spec.js index 766249d..e93a981 100644 --- a/__tests__/bootstrap.spec.js +++ b/__tests__/bootstrap.spec.js @@ -5,6 +5,7 @@ import pageTracker from "@/page-tracker"; import optOut from "@/api/opt-out"; import * as util from "@/util"; +jest.mock("@/api/config"); jest.mock("@/page-tracker"); jest.mock("@/api/opt-out"); jest.mock("@/install"); diff --git a/src/api/pageview.js b/src/api/pageview.js index 2b1aab4..14d3fb5 100644 --- a/src/api/pageview.js +++ b/src/api/pageview.js @@ -1,4 +1,4 @@ -import event from "./event"; +import config from "./config"; export default (...args) => { const [arg] = args; @@ -13,5 +13,5 @@ export default (...args) => { params = arg; } - event("page_view", params); + config(params); }; diff --git a/src/bootstrap.js b/src/bootstrap.js index f732008..49943ea 100644 --- a/src/bootstrap.js +++ b/src/bootstrap.js @@ -1,4 +1,5 @@ import { warn, isFn, loadScript } from "./util"; +import config from "./api/config"; import { getOptions } from "../src/install"; import optOut from "./api/opt-out"; import pageTracker from "./page-tracker"; @@ -11,7 +12,7 @@ export default function() { const { enabled, globalObjectName, - config, + config: { id }, pageTrackerEnabled, onReady, disableScriptLoad @@ -30,6 +31,8 @@ export default function() { window[globalObjectName]("js", new Date()); + config(); + if (pageTrackerEnabled) { pageTracker(); } @@ -39,7 +42,7 @@ export default function() { } const domain = "https://www.googletagmanager.com"; - const resource = `${domain}/gtag/js?id=${config.id}`; + const resource = `${domain}/gtag/js?id=${id}`; return loadScript(resource, domain) .then(() => {