Skip to content

Commit

Permalink
fix: no data reporting (#145)
Browse files Browse the repository at this point in the history
add config at start and config at pageview instead of page_view event

closes #144
closes #143
  • Loading branch information
MatteoGabriele committed Jun 16, 2020
1 parent 32b66c5 commit 9695d22
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
8 changes: 4 additions & 4 deletions __tests__/api/pageview.spec.js
Original file line number Diff line number Diff line change
@@ -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" });
});
});
1 change: 1 addition & 0 deletions __tests__/bootstrap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/api/pageview.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import event from "./event";
import config from "./config";

export default (...args) => {
const [arg] = args;
Expand All @@ -13,5 +13,5 @@ export default (...args) => {
params = arg;
}

event("page_view", params);
config(params);
};
7 changes: 5 additions & 2 deletions src/bootstrap.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -11,7 +12,7 @@ export default function() {
const {
enabled,
globalObjectName,
config,
config: { id },
pageTrackerEnabled,
onReady,
disableScriptLoad
Expand All @@ -30,6 +31,8 @@ export default function() {

window[globalObjectName]("js", new Date());

config();

if (pageTrackerEnabled) {
pageTracker();
}
Expand All @@ -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(() => {
Expand Down

0 comments on commit 9695d22

Please sign in to comment.