ga-4-react
Advanced tools
Comparing version 0.1.23 to 0.1.24
@@ -50,3 +50,4 @@ 'use strict'; | ||
event: this.event, | ||
gtag: this.gtag | ||
gtag: this.gtag, | ||
ga: this.ga | ||
}); | ||
@@ -96,2 +97,12 @@ }; | ||
/** | ||
* @desc direct access to ga | ||
* @param args | ||
*/ | ||
ga() { | ||
//@ts-ignore | ||
return window.ga(...arguments); | ||
} | ||
/** | ||
* @desc direct access to gtag | ||
@@ -116,11 +127,22 @@ * @param args | ||
} = _ref; | ||
var [components, setComponents] = React.useState(children); | ||
var [components, setComponents] = React.useState(null); | ||
React.useEffect(() => { | ||
var ga4manager = new GA4React("" + code, config, additionalCode); | ||
ga4manager.initialize().then(ga4 => { | ||
console.log('yy', ga4); | ||
setComponents(React__default.Children.map(children, (child, index) => { | ||
return React__default.cloneElement(child, { | ||
ga4: ga4, | ||
index | ||
}); | ||
if (!React__default.isValidElement(child)) { | ||
return React__default.createElement(React__default.Fragment, null, child); | ||
} else { | ||
//@ts-ignore | ||
if (child.type && typeof child.type.name !== 'undefined') { | ||
return React__default.cloneElement(child, { | ||
//@ts-ignore | ||
ga4: ga4, | ||
index | ||
}); | ||
} else { | ||
return child; | ||
} | ||
} | ||
})); | ||
@@ -127,0 +149,0 @@ }, err => { |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),a=(e=t)&&"object"==typeof e&&"default"in e?e.default:e;class n{constructor(e,t,a){this.gaCode=e,this.config=t,this.additionalGaCode=a,this.config=t||{},this.gaCode=e}initialize(){return new Promise((e,t)=>{var a=document.getElementsByTagName("head")[0],n=document.createElement("script");n.setAttribute("async",""),n.setAttribute("src","https://www.googletagmanager.com/gtag/js?id="+this.gaCode),n.onload=()=>{var t=document.createElement("script"),n="\n window.dataLayer = window.dataLayer || [];\n function gtag(){dataLayer.push(arguments);}\n gtag('js', new Date());\n gtag('config', '"+this.gaCode+"', "+JSON.stringify(this.config)+");";this.additionalGaCode&&this.additionalGaCode.forEach(e=>{n+="gtag('config', '"+e+"');"}),t.innerHTML=n,a.appendChild(t),e({pageview:this.pageview,event:this.event,gtag:this.gtag})},n.onerror=e=>{t(e)},a.appendChild(n)})}pageview(e){return this.gtag("event","page_view",{page_path:e,page_location:window.location,page_title:document.title})}event(e,t,a,n){return void 0===n&&(n=!1),this.gtag("event",e,{event_label:t,event_category:a,non_interaction:n})}gtag(){return window.gtag(...arguments)}}exports.GA4R=e=>{var{code:i,config:o,additionalCode:r,children:g}=e,[d,s]=t.useState(g);return t.useEffect(()=>{new n(""+i,o,r).initialize().then(e=>{s(a.Children.map(g,(t,n)=>a.cloneElement(t,{ga4:e,index:n})))},e=>{console.error(e)})},[]),a.createElement(a.Fragment,null,d)},exports.default=n; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),a=(e=t)&&"object"==typeof e&&"default"in e?e.default:e;class n{constructor(e,t,a){this.gaCode=e,this.config=t,this.additionalGaCode=a,this.config=t||{},this.gaCode=e}initialize(){return new Promise((e,t)=>{var a=document.getElementsByTagName("head")[0],n=document.createElement("script");n.setAttribute("async",""),n.setAttribute("src","https://www.googletagmanager.com/gtag/js?id="+this.gaCode),n.onload=()=>{var t=document.createElement("script"),n="\n window.dataLayer = window.dataLayer || [];\n function gtag(){dataLayer.push(arguments);}\n gtag('js', new Date());\n gtag('config', '"+this.gaCode+"', "+JSON.stringify(this.config)+");";this.additionalGaCode&&this.additionalGaCode.forEach(e=>{n+="gtag('config', '"+e+"');"}),t.innerHTML=n,a.appendChild(t),e({pageview:this.pageview,event:this.event,gtag:this.gtag,ga:this.ga})},n.onerror=e=>{t(e)},a.appendChild(n)})}pageview(e){return this.gtag("event","page_view",{page_path:e,page_location:window.location,page_title:document.title})}event(e,t,a,n){return void 0===n&&(n=!1),this.gtag("event",e,{event_label:t,event_category:a,non_interaction:n})}ga(){return window.ga(...arguments)}gtag(){return window.gtag(...arguments)}}exports.GA4R=e=>{var{code:i,config:o,additionalCode:r,children:g}=e,[d,s]=t.useState(null);return t.useEffect(()=>{new n(""+i,o,r).initialize().then(e=>{console.log("yy",e),s(a.Children.map(g,(t,n)=>a.isValidElement(t)?t.type&&void 0!==t.type.name?a.cloneElement(t,{ga4:e,index:n}):t:a.createElement(a.Fragment,null,t)))},e=>{console.error(e)})},[]),a.createElement(a.Fragment,null,d)},exports.default=n; | ||
//# sourceMappingURL=ga-4-react.cjs.production.min.js.map |
@@ -43,3 +43,4 @@ import React, { useState, useEffect } from 'react'; | ||
event: this.event, | ||
gtag: this.gtag | ||
gtag: this.gtag, | ||
ga: this.ga | ||
}); | ||
@@ -89,2 +90,12 @@ }; | ||
/** | ||
* @desc direct access to ga | ||
* @param args | ||
*/ | ||
ga() { | ||
//@ts-ignore | ||
return window.ga(...arguments); | ||
} | ||
/** | ||
* @desc direct access to gtag | ||
@@ -109,11 +120,22 @@ * @param args | ||
} = _ref; | ||
var [components, setComponents] = useState(children); | ||
var [components, setComponents] = useState(null); | ||
useEffect(() => { | ||
var ga4manager = new GA4React("" + code, config, additionalCode); | ||
ga4manager.initialize().then(ga4 => { | ||
console.log('yy', ga4); | ||
setComponents(React.Children.map(children, (child, index) => { | ||
return React.cloneElement(child, { | ||
ga4: ga4, | ||
index | ||
}); | ||
if (!React.isValidElement(child)) { | ||
return React.createElement(React.Fragment, null, child); | ||
} else { | ||
//@ts-ignore | ||
if (child.type && typeof child.type.name !== 'undefined') { | ||
return React.cloneElement(child, { | ||
//@ts-ignore | ||
ga4: ga4, | ||
index | ||
}); | ||
} else { | ||
return child; | ||
} | ||
} | ||
})); | ||
@@ -120,0 +142,0 @@ }, err => { |
@@ -35,2 +35,7 @@ import { ga4Config, GA4ReactInterface, GA4ReactResolveInterface, gtagAction, gtagCategory, gtagFunction, gtagLabel } from './gtagModels'; | ||
/** | ||
* @desc direct access to ga | ||
* @param args | ||
*/ | ||
ga(...args: any): any; | ||
/** | ||
* @desc direct access to gtag | ||
@@ -37,0 +42,0 @@ * @param args |
@@ -44,2 +44,3 @@ export declare type gtagEvent = 'event' | string; | ||
gtag(...args: any): any; | ||
ga(...args: any): any; | ||
} | ||
@@ -52,2 +53,3 @@ /** | ||
send_page_view: boolean; | ||
groups: string; | ||
} |
{ | ||
"version": "0.1.23", | ||
"version": "0.1.24", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
48152
20
661
0