Skip to content

Commit 5c47362

Browse files
Fix jsconfig.json file, update .npmignore and update examples
1 parent e61369f commit 5c47362

File tree

14 files changed

+5251
-93
lines changed

14 files changed

+5251
-93
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.github/
12
node_modules/
23
dist/
34
examples/

README.md

Lines changed: 60 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,87 @@
11
# GTM Sandboxed API IntelliSense
22

3-
43
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.
54

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:
196
- `server-gtm-sandboxed-apis.d.ts`: For **Server-side** GTM templates.
207
- `web-gtm-sandboxed-apis.d.ts`: For **Web** GTM templates.
218

22-
---
23-
24-
## What Are These Files?
9+
## What Are These Definitions?
2510

2611
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.
2712

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.
2914

3015

3116
https://github.com/user-attachments/assets/868bbe2c-3e28-47b1-b195-cdfc509ec340
3217

33-
3418
---
3519

3620
## How to Use
3721

22+
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).
3839

39-
After installing the package, you can reference the type definitions in your project as follows:
40+
- For **Web** GTM Sandboxed APIs:
41+
```javascript
42+
/// <reference types="stape-gtm-api-types/web-gtm-sandboxed-apis" />
4043
41-
### Method 1: Using a Triple-Slash Directive (File-by-File)
44+
// Your GTM template code starts here...
45+
const copyFromDataLayer = require('copyFromDataLayer');
46+
```
4247

43-
Add a special comment to the **very top** of each JavaScript file where you want IntelliSense:
48+
- For **Server** GTM Sandboxed APIs:
49+
```javascript
50+
/// <reference types="stape-gtm-api-types/server-gtm-sandboxed-apis" />
4451
45-
```javascript
46-
/// <reference types="stape-gtm-api-types/web-gtm-sandboxed-apis" />
47-
// or
48-
/// <reference types="stape-gtm-api-types/server-gtm-sandboxed-apis" />
49-
```
52+
// Your GTM template code starts here...
53+
const getAllEventData = require('getAllEventData');
54+
```
5055

51-
Choose the appropriate type for your environment (Web or Server).
56+
### Method 2: Using `jsconfig.json`
5257

53-
### Method 2: Using `jsconfig.json` or `tsconfig.json`
58+
Create a `jsconfig.json` containing the following content in your project's root directory where the code of your template is located.
5459
55-
Add the package to your `jsconfig.json` or `tsconfig.json`:
60+
- For **Web** GTM Sandboxed APIs:
61+
```json
62+
{
63+
"compilerOptions": {
64+
"paths": {
65+
"*": ["./node_modules/stape-gtm-api-types/web-gtm-sandboxed-apis"]
66+
}
67+
},
68+
"include": ["**/*"]
69+
}
70+
```
5671
57-
```json
58-
{
59-
"compilerOptions": {
60-
"typeRoots": ["./node_modules/stape-gtm-api-types"]
61-
},
62-
"include": ["**/*"]
63-
}
64-
```
72+
- For **Server** GTM Sandboxed APIs:
73+
```json
74+
{
75+
"compilerOptions": {
76+
"paths": {
77+
"*": ["./node_modules/stape-gtm-api-types/server-gtm-sandboxed-apis"]
78+
}
79+
},
80+
"include": ["**/*"]
81+
}
82+
```
6583
66-
Reload your editor if IntelliSense does not appear immediately.
84+
3. Reload your editor if IntelliSense does not appear immediately.
6785
6886
---
6987
@@ -72,15 +90,15 @@ Reload your editor if IntelliSense does not appear immediately.
7290
7391
### Visual Studio Code
7492
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.
7694
7795
### JetBrains IDEs (WebStorm, IntelliJ IDEA, etc.)
7896
79-
JetBrains IDEs will automatically index type definitions from installed npm packages. No manual copying required.
97+
JetBrains IDEs will automatically index type definitions from installed `npm` packages. No manual copying required.
8098
8199
### Other Editors (Sublime Text, Neovim, etc.)
82100
83-
Other editors that support TypeScript/JavaScript language servers will automatically detect type definitions from npm packages.
101+
Other editors that support TypeScript/JavaScript language servers will automatically detect type definitions from `npm` packages.
84102
85103
---
86104

0 commit comments

Comments
 (0)