@gudhub/ssg-web-components-library 1.0.67 → 1.0.68

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gudhub/ssg-web-components-library",
3
- "version": "1.0.67",
3
+ "version": "1.0.68",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -0,0 +1,6 @@
1
+ export const GoogleAnalytics = {
2
+ tag: 'google-analytics',
3
+ category: 'Utilities',
4
+ src: '@gudhub/ssg-web-components-library/src/components/google-analytics/google-analytics.js',
5
+ serverOnly: false
6
+ }
@@ -0,0 +1,41 @@
1
+ class GoogleAnalytics extends GHComponent {
2
+ constructor() {
3
+ super();
4
+ }
5
+
6
+ onClientRender() {
7
+ const timeout = parseInt(this.getAttribute('data-timeout')) || 3000;
8
+ const googleId = this.getAttribute('data-googleId');
9
+ const script = document.createElement('script');
10
+
11
+ if (!googleId) {
12
+ script.innerHTML = 'No google id for analytics'
13
+ } else {
14
+ script.innerHTML = `
15
+ window.addEventListener('load', function () {
16
+ setTimeout(function () {
17
+ const gtagScript = document.createElement('script');
18
+ gtagScript.src = 'https://www.googletagmanager.com/gtag/js?id=${googleId}';
19
+ gtagScript.async = true;
20
+ document.head.appendChild(gtagScript);
21
+
22
+ gtagScript.onload = function () {
23
+ window.dataLayer = window.dataLayer || [];
24
+ function gtag() {
25
+ dataLayer.push(arguments);
26
+ }
27
+ window.gtag = gtag;
28
+ gtag('js', new Date());
29
+ gtag('config', '${googleId}');
30
+ };
31
+ }, ${timeout});
32
+ });
33
+ `;
34
+ }
35
+
36
+ document.querySelector('body').appendChild(script);
37
+ this.remove();
38
+ }
39
+ }
40
+
41
+ window.customElements.define('google-analytics', GoogleAnalytics);
package/src/config.js CHANGED
@@ -61,8 +61,10 @@ export { htmlTemplate } from './components/html-template/config.js';
61
61
  export { masonryGallery } from './components/masonry-gallery/config.js';
62
62
  export { pageBannerWithVideo } from './components/page-banner-with-video/config.js';
63
63
  export { youtubePlayer } from './components/youtube-player/config.js';
64
- export { getInTouchBlockWithImage } from './components/get-in-touch-block-with-image/config.js'
65
- export { PageBannerImageAndMenu } from './components/page-banner-image-and-menu/config.js'
64
+ export { getInTouchBlockWithImage } from './components/get-in-touch-block-with-image/config.js';
65
+ export { PageBannerImageAndMenu } from './components/page-banner-image-and-menu/config.js';
66
+ export { GoogleAnalytics } from './components/google-analytics/config.js';
67
+
66
68
 
67
69
 
68
70
  // export { liqPayComponent } from './components/liqpay-component/config.js';