@faskai/ui-commons 0.0.0-alpha.1
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 +80 -0
- package/dist/components/gtm/gtm-provider.d.ts +18 -0
- package/dist/components/gtm/gtm-provider.js +72 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Fask UI Commons
|
|
2
|
+
|
|
3
|
+
A minimal package containing common UI components and utilities shared between Fask applications:
|
|
4
|
+
|
|
5
|
+
* @/fask-web-app-v2 (B2C) is hosted at fask.ai
|
|
6
|
+
* @/fask-biz-landing (B2B landing) is at fask.ai/business
|
|
7
|
+
* @/powpal-web-app (B2B dashboard) is at biz.fask.ai
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
yarn add @faskai/ui-commons@0.0.0-alpha.01
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### GTM Provider
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { GTMProvider } from '@faskai/ui-commons';
|
|
21
|
+
|
|
22
|
+
function App() {
|
|
23
|
+
return (
|
|
24
|
+
<GTMProvider gtmId="GTM-K62S389H">
|
|
25
|
+
{/* Your app content */}
|
|
26
|
+
</GTMProvider>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Tracking Events
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import { trackEvent, trackConversion, trackLinkedInConversion } from '@faskai/ui-commons';
|
|
35
|
+
|
|
36
|
+
// Track custom events
|
|
37
|
+
trackEvent('button_click', { button_name: 'signup' });
|
|
38
|
+
|
|
39
|
+
// Track Google Ads conversions
|
|
40
|
+
trackConversion('AW-17123441126', 'DshBCLKT8s4aEObzi-U_');
|
|
41
|
+
|
|
42
|
+
// Track LinkedIn conversions
|
|
43
|
+
trackLinkedInConversion('123456789');
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Development
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Install dependencies
|
|
50
|
+
yarn install
|
|
51
|
+
|
|
52
|
+
# Build the package
|
|
53
|
+
yarn build
|
|
54
|
+
|
|
55
|
+
# Watch for changes
|
|
56
|
+
yarn dev
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Publishing
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# Build and publish to npm
|
|
63
|
+
yarn build
|
|
64
|
+
yarn publish
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Adding New Components
|
|
68
|
+
|
|
69
|
+
1. Create your component in `src/components/`
|
|
70
|
+
2. Export it from `src/index.ts`
|
|
71
|
+
3. Build the package with `yarn build`
|
|
72
|
+
4. The component will be available in all consuming projects
|
|
73
|
+
|
|
74
|
+
## Current Components
|
|
75
|
+
|
|
76
|
+
- **GTMProvider**: Google Tag Manager integration
|
|
77
|
+
- **trackEvent**: Custom event tracking
|
|
78
|
+
- **trackConversion**: Google Ads conversion tracking
|
|
79
|
+
- **trackLinkedInConversion**: LinkedIn Ads conversion tracking
|
|
80
|
+
- **trackLinkedInLead**: LinkedIn lead tracking
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
dataLayer: any[];
|
|
5
|
+
gtag: (...args: any[]) => void;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
interface GTMProviderProps {
|
|
9
|
+
gtmId: string;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
environment?: 'development' | 'production';
|
|
12
|
+
}
|
|
13
|
+
export declare function GTMProvider({ gtmId, children, environment }: GTMProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare function trackEvent(eventName: string, parameters?: Record<string, any>): void;
|
|
15
|
+
export declare function trackConversion(conversionId: string, conversionLabel?: string, value?: number): void;
|
|
16
|
+
export declare function trackLinkedInConversion(conversionId: string, value?: number): void;
|
|
17
|
+
export declare function trackLinkedInLead(): void;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
export function GTMProvider({ gtmId, children, environment = 'production' }) {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
// Initialize dataLayer
|
|
6
|
+
window.dataLayer = window.dataLayer || [];
|
|
7
|
+
// Load GTM script
|
|
8
|
+
const script = document.createElement('script');
|
|
9
|
+
script.innerHTML = `
|
|
10
|
+
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
|
11
|
+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
|
12
|
+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
|
13
|
+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
|
14
|
+
})(window,document,'script','dataLayer','${gtmId}');
|
|
15
|
+
`;
|
|
16
|
+
document.head.appendChild(script);
|
|
17
|
+
// Add noscript iframe
|
|
18
|
+
const noscript = document.createElement('noscript');
|
|
19
|
+
const iframe = document.createElement('iframe');
|
|
20
|
+
iframe.src = `https://www.googletagmanager.com/ns.html?id=${gtmId}`;
|
|
21
|
+
iframe.height = '0';
|
|
22
|
+
iframe.width = '0';
|
|
23
|
+
iframe.style.display = 'none';
|
|
24
|
+
iframe.style.visibility = 'hidden';
|
|
25
|
+
noscript.appendChild(iframe);
|
|
26
|
+
document.body.insertBefore(noscript, document.body.firstChild);
|
|
27
|
+
return () => {
|
|
28
|
+
// Cleanup
|
|
29
|
+
if (script.parentNode) {
|
|
30
|
+
script.parentNode.removeChild(script);
|
|
31
|
+
}
|
|
32
|
+
if (noscript.parentNode) {
|
|
33
|
+
noscript.parentNode.removeChild(noscript);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}, [gtmId]);
|
|
37
|
+
return _jsx(_Fragment, { children: children });
|
|
38
|
+
}
|
|
39
|
+
// Helper function to track custom events
|
|
40
|
+
export function trackEvent(eventName, parameters) {
|
|
41
|
+
if (typeof window !== 'undefined' && window.dataLayer) {
|
|
42
|
+
window.dataLayer.push({
|
|
43
|
+
event: eventName,
|
|
44
|
+
...parameters,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Helper function to track conversions
|
|
49
|
+
export function trackConversion(conversionId, conversionLabel, value) {
|
|
50
|
+
if (typeof window !== 'undefined' && window.gtag) {
|
|
51
|
+
window.gtag('event', 'conversion', {
|
|
52
|
+
send_to: conversionLabel ? `${conversionId}/${conversionLabel}` : conversionId,
|
|
53
|
+
value: value,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Helper function to track LinkedIn conversions
|
|
58
|
+
export function trackLinkedInConversion(conversionId, value) {
|
|
59
|
+
trackEvent('linkedin_conversion', {
|
|
60
|
+
conversion_id: conversionId,
|
|
61
|
+
value: value,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// Helper function to track LinkedIn leads
|
|
65
|
+
export function trackLinkedInLead() {
|
|
66
|
+
if (typeof window !== 'undefined') {
|
|
67
|
+
trackEvent('linkedin_lead', {
|
|
68
|
+
page_location: window.location.href,
|
|
69
|
+
page_title: document.title,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GTMProvider, trackConversion, trackEvent, trackLinkedInConversion, trackLinkedInLead } from './components/gtm/gtm-provider';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GTMProvider, trackConversion, trackEvent, trackLinkedInConversion, trackLinkedInLead } from './components/gtm/gtm-provider';
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@faskai/ui-commons",
|
|
3
|
+
"author": "Fask AI <arko@fask.ai>",
|
|
4
|
+
"version": "0.0.0-alpha.01",
|
|
5
|
+
"description": "Common UI components and utilities for Fask applications",
|
|
6
|
+
"private": false,
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"module": "dist/index.esm.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"browser": "dist/index.esm.js",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./dist/index.esm.js",
|
|
19
|
+
"require": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc",
|
|
25
|
+
"dev": "tsc --watch",
|
|
26
|
+
"clean": "rm -rf dist",
|
|
27
|
+
"prepare": "yarn build"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"next": "^14.0.0",
|
|
31
|
+
"react": "^18.0.0",
|
|
32
|
+
"react-dom": "^18.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/react": "^18.0.0",
|
|
36
|
+
"@types/react-dom": "^18.0.0",
|
|
37
|
+
"@types/node": "^20.0.0",
|
|
38
|
+
"typescript": "^5.0.0",
|
|
39
|
+
"react": "^18.0.0",
|
|
40
|
+
"react-dom": "^18.0.0"
|
|
41
|
+
},
|
|
42
|
+
"packageManager": "yarn@1.22.22"
|
|
43
|
+
}
|