ninetwo-user-tracking 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.js +67 -23
- package/dist/index.mjs +67 -23
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -120,34 +120,78 @@ var TrackingProvider = ({
|
|
|
120
120
|
useAutoTrackSubmit(true);
|
|
121
121
|
(0, import_react3.useEffect)(() => {
|
|
122
122
|
if (!gtmId || typeof window === "undefined") {
|
|
123
|
-
if (debug && !gtmId)
|
|
124
|
-
console.warn("[NineTwo Tracking]
|
|
123
|
+
if (debug && !gtmId) {
|
|
124
|
+
console.warn("[NineTwo Tracking] Nenhum ID fornecido.");
|
|
125
|
+
}
|
|
125
126
|
return;
|
|
126
127
|
}
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
const isGA4 = gtmId.startsWith("G-");
|
|
129
|
+
const isGTM = gtmId.startsWith("GTM-");
|
|
130
|
+
if (!isGA4 && !isGTM) {
|
|
131
|
+
console.warn("[NineTwo Tracking] ID inv\xE1lido:", gtmId);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const existing = document.querySelector(
|
|
135
|
+
`script[data-ninetwo-tracking="${gtmId}"]`
|
|
136
|
+
);
|
|
137
|
+
if (existing) {
|
|
138
|
+
if (debug) {
|
|
139
|
+
console.log("[NineTwo Tracking] Script j\xE1 carregado:", gtmId);
|
|
140
|
+
}
|
|
131
141
|
return;
|
|
132
142
|
}
|
|
133
143
|
window.dataLayer = window.dataLayer || [];
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
console.error("[NineTwo Tracking]
|
|
149
|
-
|
|
150
|
-
|
|
144
|
+
if (isGA4) {
|
|
145
|
+
if (debug) {
|
|
146
|
+
console.log("[NineTwo Tracking] Inicializando GA4:", gtmId);
|
|
147
|
+
}
|
|
148
|
+
const gtagScript = document.createElement("script");
|
|
149
|
+
gtagScript.async = true;
|
|
150
|
+
gtagScript.src = `https://www.googletagmanager.com/gtag/js?id=${gtmId}`;
|
|
151
|
+
gtagScript.setAttribute("data-ninetwo-tracking", gtmId);
|
|
152
|
+
gtagScript.onload = () => {
|
|
153
|
+
if (debug) {
|
|
154
|
+
console.log("[NineTwo Tracking] gtag.js carregado com sucesso");
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
gtagScript.onerror = () => {
|
|
158
|
+
console.error("[NineTwo Tracking] Erro ao carregar gtag.js");
|
|
159
|
+
};
|
|
160
|
+
document.head.appendChild(gtagScript);
|
|
161
|
+
const inlineScript = document.createElement("script");
|
|
162
|
+
inlineScript.setAttribute("data-ninetwo-tracking", `${gtmId}-inline`);
|
|
163
|
+
inlineScript.innerHTML = `
|
|
164
|
+
window.dataLayer = window.dataLayer || [];
|
|
165
|
+
function gtag(){dataLayer.push(arguments);}
|
|
166
|
+
gtag('js', new Date());
|
|
167
|
+
gtag('config', '${gtmId}', {
|
|
168
|
+
send_page_view: true
|
|
169
|
+
});
|
|
170
|
+
`;
|
|
171
|
+
document.head.appendChild(inlineScript);
|
|
172
|
+
}
|
|
173
|
+
if (isGTM) {
|
|
174
|
+
if (debug) {
|
|
175
|
+
console.log("[NineTwo Tracking] Inicializando GTM:", gtmId);
|
|
176
|
+
}
|
|
177
|
+
window.dataLayer.push({
|
|
178
|
+
"gtm.start": (/* @__PURE__ */ new Date()).getTime(),
|
|
179
|
+
event: "gtm.js"
|
|
180
|
+
});
|
|
181
|
+
const gtmScript = document.createElement("script");
|
|
182
|
+
gtmScript.async = true;
|
|
183
|
+
gtmScript.src = `https://www.googletagmanager.com/gtm.js?id=${gtmId}`;
|
|
184
|
+
gtmScript.setAttribute("data-ninetwo-tracking", gtmId);
|
|
185
|
+
gtmScript.onload = () => {
|
|
186
|
+
if (debug) {
|
|
187
|
+
console.log("[NineTwo Tracking] GTM carregado com sucesso");
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
gtmScript.onerror = () => {
|
|
191
|
+
console.error("[NineTwo Tracking] Erro ao carregar GTM");
|
|
192
|
+
};
|
|
193
|
+
document.head.appendChild(gtmScript);
|
|
194
|
+
}
|
|
151
195
|
}, [gtmId, debug]);
|
|
152
196
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
|
|
153
197
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -92,34 +92,78 @@ var TrackingProvider = ({
|
|
|
92
92
|
useAutoTrackSubmit(true);
|
|
93
93
|
useEffect3(() => {
|
|
94
94
|
if (!gtmId || typeof window === "undefined") {
|
|
95
|
-
if (debug && !gtmId)
|
|
96
|
-
console.warn("[NineTwo Tracking]
|
|
95
|
+
if (debug && !gtmId) {
|
|
96
|
+
console.warn("[NineTwo Tracking] Nenhum ID fornecido.");
|
|
97
|
+
}
|
|
97
98
|
return;
|
|
98
99
|
}
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
const isGA4 = gtmId.startsWith("G-");
|
|
101
|
+
const isGTM = gtmId.startsWith("GTM-");
|
|
102
|
+
if (!isGA4 && !isGTM) {
|
|
103
|
+
console.warn("[NineTwo Tracking] ID inv\xE1lido:", gtmId);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const existing = document.querySelector(
|
|
107
|
+
`script[data-ninetwo-tracking="${gtmId}"]`
|
|
108
|
+
);
|
|
109
|
+
if (existing) {
|
|
110
|
+
if (debug) {
|
|
111
|
+
console.log("[NineTwo Tracking] Script j\xE1 carregado:", gtmId);
|
|
112
|
+
}
|
|
103
113
|
return;
|
|
104
114
|
}
|
|
105
115
|
window.dataLayer = window.dataLayer || [];
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
console.error("[NineTwo Tracking]
|
|
121
|
-
|
|
122
|
-
|
|
116
|
+
if (isGA4) {
|
|
117
|
+
if (debug) {
|
|
118
|
+
console.log("[NineTwo Tracking] Inicializando GA4:", gtmId);
|
|
119
|
+
}
|
|
120
|
+
const gtagScript = document.createElement("script");
|
|
121
|
+
gtagScript.async = true;
|
|
122
|
+
gtagScript.src = `https://www.googletagmanager.com/gtag/js?id=${gtmId}`;
|
|
123
|
+
gtagScript.setAttribute("data-ninetwo-tracking", gtmId);
|
|
124
|
+
gtagScript.onload = () => {
|
|
125
|
+
if (debug) {
|
|
126
|
+
console.log("[NineTwo Tracking] gtag.js carregado com sucesso");
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
gtagScript.onerror = () => {
|
|
130
|
+
console.error("[NineTwo Tracking] Erro ao carregar gtag.js");
|
|
131
|
+
};
|
|
132
|
+
document.head.appendChild(gtagScript);
|
|
133
|
+
const inlineScript = document.createElement("script");
|
|
134
|
+
inlineScript.setAttribute("data-ninetwo-tracking", `${gtmId}-inline`);
|
|
135
|
+
inlineScript.innerHTML = `
|
|
136
|
+
window.dataLayer = window.dataLayer || [];
|
|
137
|
+
function gtag(){dataLayer.push(arguments);}
|
|
138
|
+
gtag('js', new Date());
|
|
139
|
+
gtag('config', '${gtmId}', {
|
|
140
|
+
send_page_view: true
|
|
141
|
+
});
|
|
142
|
+
`;
|
|
143
|
+
document.head.appendChild(inlineScript);
|
|
144
|
+
}
|
|
145
|
+
if (isGTM) {
|
|
146
|
+
if (debug) {
|
|
147
|
+
console.log("[NineTwo Tracking] Inicializando GTM:", gtmId);
|
|
148
|
+
}
|
|
149
|
+
window.dataLayer.push({
|
|
150
|
+
"gtm.start": (/* @__PURE__ */ new Date()).getTime(),
|
|
151
|
+
event: "gtm.js"
|
|
152
|
+
});
|
|
153
|
+
const gtmScript = document.createElement("script");
|
|
154
|
+
gtmScript.async = true;
|
|
155
|
+
gtmScript.src = `https://www.googletagmanager.com/gtm.js?id=${gtmId}`;
|
|
156
|
+
gtmScript.setAttribute("data-ninetwo-tracking", gtmId);
|
|
157
|
+
gtmScript.onload = () => {
|
|
158
|
+
if (debug) {
|
|
159
|
+
console.log("[NineTwo Tracking] GTM carregado com sucesso");
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
gtmScript.onerror = () => {
|
|
163
|
+
console.error("[NineTwo Tracking] Erro ao carregar GTM");
|
|
164
|
+
};
|
|
165
|
+
document.head.appendChild(gtmScript);
|
|
166
|
+
}
|
|
123
167
|
}, [gtmId, debug]);
|
|
124
168
|
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
125
169
|
};
|