@jenil_121/ga-bridge 1.0.1 → 1.0.3
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 +18 -21
- package/dist/twinalyze-ga-bridge.min.js +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
# Twinalyze GA Bridge
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A lightweight bridge to forward Google Analytics (`gtag.js`) events to Twinalyze automatically.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This allows you to use Google Analytics as the source of truth and mirror the same events into Twinalyze without modifying existing tracking code.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- wraps GA4 `gtag('event', eventName, params)` calls
|
|
9
|
-
- lets GA handle the event first
|
|
10
|
-
- then sends the same event to `window.twinalyze.track(eventName, params)`
|
|
11
|
-
- optionally validates GA-safe event names
|
|
12
|
-
- queues events if Twinalyze SDK is not ready yet
|
|
7
|
+
---
|
|
13
8
|
|
|
14
|
-
##
|
|
9
|
+
## 🚀 Features
|
|
15
10
|
|
|
16
|
-
- `
|
|
17
|
-
-
|
|
11
|
+
- Forward GA events (`gtag('event', ...)`) to Twinalyze
|
|
12
|
+
- Uses **GA callback-based forwarding** (Amplitude-like strict mode)
|
|
13
|
+
- Ensures:
|
|
14
|
+
- If GA event succeeds → Twinalyze receives it
|
|
15
|
+
- If GA event fails → Twinalyze does NOT receive it
|
|
16
|
+
- No fallback (strict dependency on GA)
|
|
17
|
+
- Automatic installation
|
|
18
|
+
- Debug mode support
|
|
19
|
+
- Adds `__from_bridge: true` flag to all forwarded events
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
---
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
## 📦 Installation
|
|
24
|
+
|
|
25
|
+
### CDN (Recommended)
|
|
22
26
|
|
|
23
27
|
```html
|
|
24
|
-
<script src="https://cdn.jsdelivr.net/npm/@
|
|
25
|
-
<script>
|
|
26
|
-
window.twinalyze.init({
|
|
27
|
-
apiKey: "PUBLIC_WRITE_KEY",
|
|
28
|
-
organization: "ORG_ID",
|
|
29
|
-
socketUrl: "https://www.twinalyze.com/"
|
|
30
|
-
});
|
|
31
|
-
</script>
|
|
28
|
+
<script src="https://cdn.jsdelivr.net/npm/@jenil_121/ga-bridge@1.0.0/dist/twinalyze-ga-bridge.min.js"></script>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e){var t={
|
|
1
|
+
!function(e){"use strict";var t={debug:!0,forwardOnlyValidEvents:!0,addBridgeFlag:!0,bridgeFlagKey:"__from_bridge",installWaitMs:1500,eventTimeout:2e3},n="__gaTwinalyzeBridgeInstalled",o=/^[A-Za-z][A-Za-z0-9_]{0,39}$/;function i(){if(!e.__TWINALYZE_GA_BRIDGE_DEBUG__)return;var t=Array.prototype.slice.call(arguments);t.unshift("[Twinalyze GA Bridge]"),console.log.apply(console,t)}function r(){var t=Array.prototype.slice.call(arguments);t.unshift("[Twinalyze GA Bridge]"),console.warn.apply(console,t)}function a(e){return e&&"object"==typeof e&&!Array.isArray(e)}function l(e){return"string"==typeof e&&o.test(e)}function g(){return e.twinalyze||e.TwinalyzeAnalytics||null}function c(){var n=e.TwinalyzeGABridgeConfig||{},o={};for(var i in t)o[i]=t[i];for(var r in n)o[r]=n[r];return o}function d(){var t=c();if(e.__TWINALYZE_GA_BRIDGE_DEBUG__=!!t.debug,e[n])return void i("already installed");if("function"!=typeof e.gtag)return void r("gtag not found");var o=g();if(!o||"function"!=typeof o.track)return void r("twinalyze.track not found");var d=e.gtag;e.gtag=function(){var n=Array.prototype.slice.call(arguments);if(i("gtag call:",n),"event"===n[0]){var o=n[1],u=a(n[2])?Object.assign({},n[2]):{};if(t.forwardOnlyValidEvents&&!l(o))return r("invalid GA event name:",o),d.apply(e,n);var p=u.event_callback;return u.event_timeout="number"==typeof u.event_timeout?u.event_timeout:t.eventTimeout,u.event_callback=function(){i("GA callback fired:",o);try{"function"==typeof p&&p()}catch(e){console.error("[Twinalyze GA Bridge] old callback error",e)}try{var n=Object.assign({},u);if(delete n.event_callback,delete n.event_timeout,t.addBridgeFlag&&(n[t.bridgeFlagKey]=!0),!(s=g())||"function"!=typeof s.track)return void r("twinalyze.track missing during forward:",o);i("forwarding event:",o,n),s.track(o,n)}catch(e){console.error("[Twinalyze GA Bridge] track error",e)}var s},d.call(e,"event",o,u)}return d.apply(e,n)},e[n]=!0,i("installed successfully")}function u(){var e=c();setTimeout(d,e.installWaitMs)}u()}(window);
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jenil_121/ga-bridge",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Twinalyze GA Bridge (GA → Twinalyze event forwarding)",
|
|
5
5
|
"main": "dist/twinalyze-ga-bridge.min.js",
|
|
6
6
|
"files": [
|
|
7
|
-
"dist"
|
|
8
|
-
"README.md"
|
|
7
|
+
"dist"
|
|
9
8
|
],
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
9
|
+
"keywords": [
|
|
10
|
+
"twinalyze",
|
|
11
|
+
"google-analytics",
|
|
12
|
+
"gtag",
|
|
13
|
+
"analytics",
|
|
14
|
+
"bridge"
|
|
15
|
+
],
|
|
16
|
+
"author": "Your Name",
|
|
17
17
|
"license": "MIT"
|
|
18
18
|
}
|