You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60-42Lines changed: 60 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,69 +1,87 @@
1
1
# GTM Sandboxed API IntelliSense
2
2
3
-
4
3
This guide explains how to use the provided TypeScript Declaration Files (`.d.ts`) to enable IntelliSense (autocompletion and hover-documentation) for Google Tag Manager's Sandboxed JavaScript APIs in your code editor.
5
4
6
-
## Now Available as an npm Package!
7
-
8
-
You can now install the type definitions directly from npm:
9
-
10
-
```bash
11
-
pnpm install -D stape-gtm-api-types
12
-
# or
13
-
npm install --save-dev stape-gtm-api-types
14
-
```
15
-
16
-
This is the recommended way to keep your GTM API types up to date.
17
-
18
-
There are two type definition files included:
5
+
There are two file definitions:
19
6
-`server-gtm-sandboxed-apis.d.ts`: For **Server-side** GTM templates.
20
7
-`web-gtm-sandboxed-apis.d.ts`: For **Web** GTM templates.
21
8
22
-
---
23
-
24
-
## What Are These Files?
9
+
## What Are These Definitions?
25
10
26
11
Google Tag Manager's custom templates run in a "sandboxed" JavaScript environment that has a special set of APIs (like `copyFromDataLayer` or `sendHttpRequest`). Standard code editors don't know about these custom APIs, so they can't provide any help as you code.
27
12
28
-
These `.d.ts` files act as a guide for your editor. They define the signatures, parameters, and documentation for every GTM API, effectively teaching your editor how the GTM environment works.
13
+
These files act as a guide for your editor. They define the signatures, parameters, and documentation for every GTM API, effectively teaching your editor how the GTM environment works.
1. Install the type definitions directly using a package manager like `npm` or `pnpm`:
23
+
```bash
24
+
pnpm install -D stape-gtm-api-types
25
+
# or
26
+
npm install --save-dev stape-gtm-api-types
27
+
```
28
+
29
+
This is the recommended way to keep your GTM API types up to date.
30
+
31
+
2. After installing the package, you can reference the type definitions in your project as follows:
32
+
33
+
### Method 1: Using a Triple-Slash Directive (File-by-File)
34
+
35
+
This method is useful if you prefer not to create a `jsconfig.json` file. You must add a special comment to the **very top** of each JavaScript file containing GTM Sandboxed API code where you want IntelliSense.
36
+
37
+
Add a special comment to the **very top** of each JavaScript file where you want IntelliSense.
38
+
Make sure to add it exactly as is (with triple slashes).
38
39
39
-
After installing the package, you can reference the type definitions in your project as follows:
Reload your editor if IntelliSense does not appear immediately.
84
+
3. Reload your editor if IntelliSense does not appear immediately.
67
85
68
86
---
69
87
@@ -72,15 +90,15 @@ Reload your editor if IntelliSense does not appear immediately.
72
90
73
91
### Visual Studio Code
74
92
75
-
Both `jsconfig.json` and the triple-slash directive methods work perfectly. The npm package approach is recommended for easier updates and maintenance.
93
+
Both methods work perfectly. The **Method 2** is recommended for easier updates and maintenance.
0 commit comments