@kylelogue/eventfoundry-tracker 0.1.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 +104 -0
- package/dist/tracker.min.js +1 -0
- package/package.json +28 -0
package/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# EventFoundry Tracker
|
|
2
|
+
|
|
3
|
+
Embedded JavaScript tracking script for EventFoundry - enables custom GA4 event tracking with a visual editor.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
### Via unpkg CDN (Recommended)
|
|
8
|
+
|
|
9
|
+
Add the script to your website's HTML:
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<!-- Latest version (auto-updates) -->
|
|
13
|
+
<script src="https://unpkg.com/@kylelogue/eventfoundry-tracker@latest/dist/tracker.min.js"
|
|
14
|
+
data-site-key="YOUR_SITE_KEY_HERE"
|
|
15
|
+
async></script>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Or pin to a specific version for production stability:
|
|
19
|
+
|
|
20
|
+
```html
|
|
21
|
+
<!-- Pinned version -->
|
|
22
|
+
<script src="https://unpkg.com/@kylelogue/eventfoundry-tracker@0.1.0/dist/tracker.min.js"
|
|
23
|
+
data-site-key="YOUR_SITE_KEY_HERE"
|
|
24
|
+
async></script>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Via npm
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install @kylelogue/eventfoundry-tracker
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
### Option 1: Auto-inject GA4
|
|
36
|
+
|
|
37
|
+
Let EventFoundry automatically inject Google Analytics 4:
|
|
38
|
+
|
|
39
|
+
```html
|
|
40
|
+
<script src="https://unpkg.com/@kylelogue/eventfoundry-tracker@latest/dist/tracker.min.js"
|
|
41
|
+
data-site-key="YOUR_SITE_KEY_HERE"
|
|
42
|
+
data-measurement-id="G-XXXXXXXXXX"
|
|
43
|
+
async></script>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Option 2: Use existing GA4
|
|
47
|
+
|
|
48
|
+
If you already have GA4 installed, EventFoundry will detect and use it:
|
|
49
|
+
|
|
50
|
+
```html
|
|
51
|
+
<!-- Your existing GA4 installation -->
|
|
52
|
+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
|
|
53
|
+
<script>
|
|
54
|
+
window.dataLayer = window.dataLayer || [];
|
|
55
|
+
function gtag(){dataLayer.push(arguments);}
|
|
56
|
+
gtag('js', new Date());
|
|
57
|
+
gtag('config', 'G-XXXXXXXXXX');
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<!-- EventFoundry Tracker -->
|
|
61
|
+
<script src="https://unpkg.com/@kylelogue/eventfoundry-tracker@latest/dist/tracker.min.js"
|
|
62
|
+
data-site-key="YOUR_SITE_KEY_HERE"
|
|
63
|
+
async></script>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## How It Works
|
|
67
|
+
|
|
68
|
+
EventFoundry Tracker runs in two modes:
|
|
69
|
+
|
|
70
|
+
1. **Tracking Mode** (default): Fetches event definitions from your EventFoundry account, attaches click listeners to elements, and sends events directly to GA4.
|
|
71
|
+
|
|
72
|
+
2. **Editor Mode**: When loaded in the EventFoundry app, enables a visual overlay for defining custom events by clicking elements on your site.
|
|
73
|
+
|
|
74
|
+
## Features
|
|
75
|
+
|
|
76
|
+
- **Lightweight**: < 1KB gzipped
|
|
77
|
+
- **Zero dependencies**: Pure vanilla JavaScript
|
|
78
|
+
- **Fast**: 1-hour localStorage caching of event definitions
|
|
79
|
+
- **Non-blocking**: Async loading won't slow down your site
|
|
80
|
+
- **Browser support**: Chrome, Firefox, Safari, Edge (ES2015+)
|
|
81
|
+
|
|
82
|
+
## Configuration
|
|
83
|
+
|
|
84
|
+
The script accepts the following attributes:
|
|
85
|
+
|
|
86
|
+
- `data-site-key` (required): Your EventFoundry site key
|
|
87
|
+
- `data-measurement-id` (optional): Your GA4 measurement ID (if not already installed)
|
|
88
|
+
|
|
89
|
+
## Development
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# Install dependencies
|
|
93
|
+
npm install
|
|
94
|
+
|
|
95
|
+
# Build for production
|
|
96
|
+
npm run build
|
|
97
|
+
|
|
98
|
+
# Development watch mode
|
|
99
|
+
npm run dev
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
MIT © Kyle Logue
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var EventFoundry=(()=>{var r=(t,e,n)=>new Promise((d,l)=>{var y=o=>{try{i(n.next(o))}catch(a){l(a)}},h=o=>{try{i(n.throw(o))}catch(a){l(a)}},i=o=>o.done?d(o.value):Promise.resolve(o.value).then(y,h);i((n=n.apply(t,e)).next())});var c=document.currentScript||document.querySelector("script[data-site-key]"),f=c==null?void 0:c.getAttribute("data-site-key"),g=window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1",m=g?"http://localhost/api/tracking/events":"https://eventfoundry.app/api/tracking/events",s="eventfoundry_definitions",v=3600*1e3;function u(){return r(this,null,function*(){if(!f){console.warn("EventFoundry: No site key found. Add data-site-key attribute to script tag.");return}try{let t=yield w();console.log("EventFoundry: Loaded event definitions:",t)}catch(t){console.error("EventFoundry: Failed to initialize:",t)}})}function w(){return r(this,null,function*(){let t=E();if(t)return console.log("EventFoundry: Using cached definitions"),t;console.log("EventFoundry: Fetching definitions from API");let e=yield fetch(`${m}?siteKey=${f}`);if(!e.ok)throw new Error(`API returned ${e.status}`);let n=yield e.json();return p(n),n})}function E(){try{let t=localStorage.getItem(s);if(!t)return null;let{data:e,timestamp:n}=JSON.parse(t);return Date.now()-n>v?(localStorage.removeItem(s),null):e}catch(t){return console.warn("EventFoundry: Cache read failed:",t),null}}function p(t){try{let e={data:t,timestamp:Date.now()};localStorage.setItem(s,JSON.stringify(e))}catch(e){console.warn("EventFoundry: Cache write failed:",e)}}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",u):u();})();
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kylelogue/eventfoundry-tracker",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "EventFoundry tracking script for custom GA4 event tracking",
|
|
5
|
+
"main": "dist/tracker.min.js",
|
|
6
|
+
"files": ["dist"],
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "node build.js",
|
|
9
|
+
"dev": "node build.js --watch",
|
|
10
|
+
"test": "echo \"No tests yet\"",
|
|
11
|
+
"serve": "./serve-test.sh",
|
|
12
|
+
"prepublishOnly": "npm run build"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/kylelogue/eventfoundry-tracker"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/kylelogue/eventfoundry-tracker#readme",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/kylelogue/eventfoundry-tracker/issues"
|
|
21
|
+
},
|
|
22
|
+
"keywords": ["analytics", "ga4", "tracking", "google-analytics", "eventfoundry"],
|
|
23
|
+
"author": "Kyle Logue",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"esbuild": "^0.27.0"
|
|
27
|
+
}
|
|
28
|
+
}
|