@jenil_121/ga-bridge 1.0.0
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 +31 -0
- package/dist/twinalyze-ga-bridge.min.js +1 -0
- package/package.json +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Twinalyze GA Bridge
|
|
2
|
+
|
|
3
|
+
Twinalyze GA Bridge is a small browser bridge file that listens to GA4 `gtag('event', ...)` calls and forwards the same event to Twinalyze using the existing Twinalyze web SDK.
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
|
|
7
|
+
- waits for `window.gtag`
|
|
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
|
|
13
|
+
|
|
14
|
+
## Files
|
|
15
|
+
|
|
16
|
+
- `src/twinalyze-ga-bridge.js` → source file
|
|
17
|
+
- `dist/twinalyze-ga-bridge.min.js` → minified build output
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
### 1. Load Twinalyze SDK
|
|
22
|
+
|
|
23
|
+
```html
|
|
24
|
+
<script src="https://cdn.jsdelivr.net/npm/@twinalyze/web-analytics@1.0.14/dist/cdn.global.min.js" integrity="sha256-MyLqo5EG9WAfTSAH96HUCFkqNxTZkhllLCON+iG0EsM=" crossorigin="anonymous"></script>
|
|
25
|
+
<script>
|
|
26
|
+
window.twinalyze.init({
|
|
27
|
+
apiKey: "PUBLIC_WRITE_KEY",
|
|
28
|
+
organization: "ORG_ID",
|
|
29
|
+
socketUrl: "https://www.twinalyze.com/"
|
|
30
|
+
});
|
|
31
|
+
</script>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e){var t={waitForGaCallback:!0,validateGaEventNames:!0,eventTimeout:2e3,debug:!1,maxWrapRetries:200,wrapRetryInterval:100,skipEvents:["page_view"]},n=/^[A-Za-z][A-Za-z0-9_]{0,39}$/,a={options:t,wrapped:!1,originalGtag:null,wrapRetries:0,queue:[]};function i(){if(a.options.debug)try{console.log.apply(console,["[TwinalyzeGABridge]"].concat([].slice.call(arguments)))}catch(e){}}function r(){try{console.warn.apply(console,["[TwinalyzeGABridge]"].concat([].slice.call(arguments)))}catch(e){}}function o(){return e.twinalyze||e.TwinalyzeAnalytics||null}function l(e){return e&&"object"==typeof e&&!Array.isArray(e)?Object.assign({},e):{}}function c(e,t){a.queue.push({eventName:e,params:t})}function u(){var e=o();if(e&&"function"==typeof e.track)for(;a.queue.length;){var t=a.queue.shift();try{e.track(t.eventName,t.params)}catch(e){r("Failed to flush queued event:",t.eventName,e)}}}function p(e,t){var n=o();if(!n||"function"!=typeof n.track)return c(e,t),void r("Twinalyze SDK not ready, queued event:",e);try{n.track(e,t)}catch(n){r("Twinalyze track failed, queued event:",e,n),c(e,t)}}function s(){if(a.wrapped)return!0;if("function"!=typeof e.gtag)return!1;a.originalGtag=e.gtag;var t=function(){var e=Array.prototype.slice.call(arguments);if("event"!==e[0])return a.originalGtag.apply(this,e);var t,o=e[1],c=l(e[2]);if(t=o,-1!==a.options.skipEvents.indexOf(t))return i("Skipping mirrored event:",o),a.originalGtag.apply(this,e);if(a.options.validateGaEventNames&&!function(e){return"string"==typeof e&&n.test(e)}(o))return r("Invalid GA event name, skipping Twinalyze mirror:",o),a.originalGtag.apply(this,e);var s=c.event_callback,g=c.event_timeout||a.options.eventTimeout;if(a.options.waitForGaCallback){var f=Object.assign({},c,{event_timeout:g,event_callback:function(){try{"function"==typeof s&&s()}catch(e){r("User event_callback failed:",e)}var e=l(c);delete e.event_callback,delete e.event_timeout,p(o,e),u()}});return a.originalGtag.call(this,"event",o,f)}var v=l(c);return delete v.event_callback,delete v.event_timeout,p(o,v),u(),a.originalGtag.apply(this,e)};return t.__twinalyzeWrapped=!0,t.__original=a.originalGtag,e.gtag=t,a.wrapped=!0,u(),i("gtag wrapped successfully"),!0}function g(){s()||(a.wrapRetries+=1,a.wrapRetries>=a.options.maxWrapRetries?r("window.gtag not found. Bridge could not attach."):setTimeout(g,a.options.wrapRetryInterval))}function f(e){a.options=Object.assign({},t,e||{}),g(),u()}e.twinalyzeGABridge={init:f,rebind:s,flushQueue:u,version:"1.0.0"},e.twinalyzeGABridgeConfig&&f(e.twinalyzeGABridgeConfig)}(window);
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jenil_121/ga-bridge",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "GA4 to Twinalyze browser bridge",
|
|
5
|
+
"main": "dist/twinalyze-ga-bridge.min.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"README.md",
|
|
9
|
+
"LICENSE"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "terser src/twinalyze-ga-bridge.js -c -m -o dist/twinalyze-ga-bridge.min.js",
|
|
13
|
+
"prepublishOnly": "npm run build"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT"
|
|
19
|
+
}
|