@hanzo/ui 0.5.16 → 0.5.19

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.
@@ -0,0 +1,10 @@
1
+ export const FB_PIXEL_ID = process.env.NEXT_PUBLIC_FACEBOOK_PIXEL_ID
2
+
3
+ export const pageview = () => {
4
+ window.fbq('track', 'PageView')
5
+ }
6
+
7
+ // https://developers.facebook.com/docs/facebook-pixel/advanced/
8
+ export const event = (name: string, options = {}) => {
9
+ window.fbq('track', name, options)
10
+ }
@@ -0,0 +1,47 @@
1
+ 'use client'
2
+
3
+ import { useEffect, useState } from 'react'
4
+ import * as gtag from './gtag'
5
+ import Script from 'next/script'
6
+ import { usePathname } from 'next/navigation'
7
+
8
+ const GoogleAnalyticsHead = () => {
9
+ return (
10
+ <script
11
+ dangerouslySetInnerHTML={{
12
+ __html: `
13
+ window.dataLayer = window.dataLayer || [];
14
+ function gtag(){dataLayer.push(arguments);}
15
+ gtag('js', new Date());
16
+
17
+ gtag('config', '${gtag.GA_TRACKING_ID}', {
18
+ page_path: window.location.pathname,
19
+ });
20
+ `,
21
+ }}
22
+ />
23
+ )
24
+ }
25
+
26
+ const GoogleAnalytics = () => {
27
+ const [loaded, setLoaded] = useState(false)
28
+ const pathname = usePathname()
29
+
30
+ useEffect(() => {
31
+ if (!loaded) return
32
+
33
+ gtag.pageview(pathname)
34
+ }, [pathname, loaded])
35
+
36
+ return (
37
+ <div>
38
+ <Script
39
+ strategy='afterInteractive'
40
+ onLoad={() => setLoaded(true)}
41
+ src={`https://www.googletagmanager.com/gtag/js?id=${gtag.GA_TRACKING_ID}`}
42
+ />
43
+ </div>
44
+ )
45
+ }
46
+
47
+ export {GoogleAnalyticsHead, GoogleAnalytics}
@@ -0,0 +1,30 @@
1
+ // specific to site. In GA Console, under each Data Stream
2
+ export const GA_TRACKING_ID = process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID
3
+
4
+ // https://developers.google.com/analytics/devguides/collection/gtagjs/pages
5
+ export const pageview = (url: string) => {
6
+ if (GA_TRACKING_ID) {
7
+ window.gtag('config', GA_TRACKING_ID, {
8
+ page_path: url,
9
+ })
10
+ }
11
+ }
12
+
13
+ // https://developers.google.com/analytics/devguides/collection/gtagjs/events
14
+ export const event = ({
15
+ action,
16
+ category,
17
+ label,
18
+ value
19
+ }: {
20
+ action: string
21
+ category: string
22
+ label: string
23
+ value: string
24
+ }) => {
25
+ window.gtag('event', action, {
26
+ event_category: category,
27
+ event_label: label,
28
+ value: value,
29
+ })
30
+ }
@@ -0,0 +1,55 @@
1
+ 'use client'
2
+
3
+ import { usePathname } from 'next/navigation'
4
+ import Script from 'next/script'
5
+ import { useEffect, useState } from 'react'
6
+ import * as fbq from './fpixel'
7
+
8
+ const FacebookPixelHead = () => {
9
+ return (
10
+ <noscript>
11
+ <img
12
+ height='1'
13
+ width='1'
14
+ style={{ display: 'none' }}
15
+ src={`https://www.facebook.com/tr?id=${fbq.FB_PIXEL_ID}&ev=PageView&noscript=1`}
16
+ />
17
+ </noscript>
18
+ )
19
+ }
20
+
21
+ const FacebookPixel = () => {
22
+ const [loaded, setLoaded] = useState(false)
23
+ const pathname = usePathname()
24
+
25
+ useEffect(() => {
26
+ if (!loaded) return
27
+
28
+ fbq.pageview()
29
+ }, [pathname, loaded])
30
+
31
+ return (
32
+ <div>
33
+ <Script
34
+ id='fb-pixel'
35
+ strategy='afterInteractive'
36
+ onLoad={() => setLoaded(true)}
37
+ dangerouslySetInnerHTML={{
38
+ __html: `
39
+ !function(f,b,e,v,n,t,s)
40
+ {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
41
+ n.callMethod.apply(n,arguments):n.queue.push(arguments)};
42
+ if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
43
+ n.queue=[];t=b.createElement(e);t.async=!0;
44
+ t.src=v;s=b.getElementsByTagName(e)[0];
45
+ s.parentNode.insertBefore(t,s)}(window, document,'script',
46
+ 'https://connect.facebook.net/en_US/fbevents.js');
47
+ fbq('init', ${fbq.FB_PIXEL_ID});
48
+ `,
49
+ }}
50
+ />
51
+ </div>
52
+ )
53
+ }
54
+
55
+ export {FacebookPixelHead, FacebookPixel}
@@ -3,6 +3,8 @@ import React, { type PropsWithChildren } from 'react'
3
3
  import Header from '../common/header'
4
4
  import type { SiteDef } from '../types'
5
5
  import getAppRouterBodyFontClasses from './get-app-router-font-classes'
6
+ import { FacebookPixelHead, FacebookPixel } from './analytics/pixel-analytics'
7
+ import { GoogleAnalytics, GoogleAnalyticsHead } from './analytics/google-analytics'
6
8
 
7
9
  // Next 14: https://nextjs.org/docs/app/building-your-application/upgrading/codemods#use-viewport-export
8
10
  const viewport = {
@@ -39,8 +41,12 @@ const RootLayout: React.FC<PropsWithChildren & {
39
41
  <head >
40
42
  {/* https://stackoverflow.com/a/75716588/11645689 */ }
41
43
  <base target='_blank' />
44
+ <FacebookPixelHead/>
45
+ <GoogleAnalyticsHead/>
42
46
  </head>
43
47
  <body className={bodyClasses}>
48
+ <FacebookPixel />
49
+ <GoogleAnalytics />
44
50
  {header && <Header siteDef={siteDef}/>}
45
51
  {children}
46
52
  </body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/ui",
3
- "version": "0.5.16",
3
+ "version": "0.5.19",
4
4
  "description": "Library that contains shared UI primitives, support for a common design system, and other boilerplate support.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
@@ -91,6 +91,8 @@
91
91
  "@mdx-js/esbuild": "^3.0.0",
92
92
  "@mdx-js/loader": "^3.0.0",
93
93
  "@mdx-js/react": "^3.0.0",
94
+ "@types/facebook-pixel": "^0.0.30",
95
+ "@types/gtag.js": "^0.0.19",
94
96
  "@types/lodash.merge": "^4.6.9",
95
97
  "@types/mdx": "^2.0.9",
96
98
  "@types/react": "^18.2.48",