Skip to content

Commit

Permalink
BREAKING CHANGE: native implementation returns tag manager instance
Browse files Browse the repository at this point in the history
  • Loading branch information
cajames committed Aug 14, 2018
1 parent d9f9ede commit 357687a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
17 changes: 7 additions & 10 deletions src/__tests__/native-entry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,19 @@ describe("NativeEntry", () => {
expect(() => native.initialize({ gtmId: null })).not.toThrowError()
});

it("should initialize `TagManager` in the global namespace by default", () => {
native.initialize({ gtmId: '1234' })
expect((global as any).TagManager).toBeDefined()
it("should return an instanciated TagManager when called", () => {
const tagManager = native.initialize({ gtmId: '1234' })
expect(tagManager).toBeTruthy()
});

it("should initialize the TagManager in the global namespace when variable defined", () => {});

it("should install GTM once when called multiple times", () => {

native.initialize({ gtmId: "123" })
const tagManager1 = native.initialize({ gtmId: "123" })
expect(tagManager1).toBeTruthy()

expect((global as any).TagManager).toBeDefined()
delete (global as any).TagManager
const tagManager2 = native.initialize({ gtmId: "123" })
expect(tagManager2).toBeFalsy()

native.initialize({ gtmId: "1234" })
expect((global as any).TagManager).not.toBeDefined()
});

});
Expand Down
6 changes: 3 additions & 3 deletions src/native-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ const initialize = (options: NativeOptions) => {
getScriptTagWithSrc(tagManager.getScriptUrl(), true)
);

const variableName = options.TagManagerVariableName || "TagManager";
(window as any)[variableName] = tagManager;

(window as any).vgtmInstalled = true;

return tagManager;

} catch (error) {
warn(error);
}
Expand Down

0 comments on commit 357687a

Please sign in to comment.