-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.html
More file actions
186 lines (165 loc) · 5.17 KB
/
Copy pathexample.html
File metadata and controls
186 lines (165 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>tiny-utm-keeper Demo</title>
<style>
body {
font-family: system-ui, -apple-system, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 2rem;
line-height: 1.6;
}
h1 { color: #333; }
.section {
background: #f5f5f5;
padding: 1rem;
border-radius: 8px;
margin: 1rem 0;
}
pre {
background: #2d2d2d;
color: #f8f8f8;
padding: 1rem;
border-radius: 4px;
overflow-x: auto;
}
button {
background: #0070f3;
color: white;
border: none;
padding: 0.5rem 1rem;
border-radius: 4px;
cursor: pointer;
margin: 0.5rem 0.5rem 0.5rem 0;
}
button:hover { background: #0051cc; }
a {
color: #0070f3;
text-decoration: none;
}
a:hover { text-decoration: underline; }
.info { color: #666; font-size: 0.9rem; }
</style>
</head>
<body>
<h1>🎯 tiny-utm-keeper Demo</h1>
<div class="section">
<h2>Current URL</h2>
<p id="current-url" class="info">Loading...</p>
<p class="info">Try adding UTM parameters to the URL: <code>?utm_source=google&utm_medium=cpc&utm_campaign=demo</code></p>
</div>
<div class="section">
<h2>Stored UTM Parameters</h2>
<pre id="stored-utms">No UTMs stored yet</pre>
<button onclick="refreshUTMs()">Refresh</button>
<button onclick="clearUTMs()">Clear Stored UTMs</button>
</div>
<div class="section">
<h2>Actions</h2>
<button onclick="captureFromURL()">Capture from Current URL</button>
<button onclick="captureCustom()">Capture Custom UTMs</button>
</div>
<div class="section">
<h2>UTM-Enhanced Links</h2>
<p>These links will include stored UTM parameters:</p>
<a id="demo-link-1" href="#">Example Link 1</a><br>
<a id="demo-link-2" href="#">Example Link 2</a><br>
<button onclick="updateLinks()">Update Links</button>
</div>
<div class="section">
<h2>Attribution Mode</h2>
<p>Current Mode: <strong id="current-mode">first-touch</strong></p>
<button onclick="setFirstTouch()">First-Touch</button>
<button onclick="setLastTouch()">Last-Touch</button>
</div>
<script type="module">
// Import from npm CDN (unpkg)
import {
init,
getUTMs,
clear,
capture,
appendToURL,
hasStoredUTMs,
getInstance
} from 'https://unpkg.com/tiny-utm-keeper@1.0.2/dist/esm/index.js';
// Initialize
const keeper = init({
mode: 'first-touch',
expirationDays: 30,
autoCapture: true
});
// Make functions available globally for demo
window.keeper = keeper;
window.getUTMs = getUTMs;
window.clear = clear;
window.capture = capture;
window.appendToURL = appendToURL;
window.hasStoredUTMs = hasStoredUTMs;
window.getInstance = getInstance;
// Functions for buttons
window.refreshUTMs = function() {
const utms = getUTMs();
const element = document.getElementById('stored-utms');
if (utms) {
element.textContent = JSON.stringify(utms, null, 2);
} else {
element.textContent = 'No UTMs stored yet';
}
updateLinks();
};
window.clearUTMs = function() {
if (clear()) {
alert('UTMs cleared successfully!');
refreshUTMs();
} else {
alert('Failed to clear UTMs');
}
};
window.captureFromURL = function() {
if (capture()) {
alert('UTMs captured from current URL!');
refreshUTMs();
} else {
alert('No UTMs found in current URL');
}
};
window.captureCustom = function() {
const customURL = 'https://example.com?utm_source=demo&utm_medium=test&utm_campaign=custom';
if (capture(customURL)) {
alert('Custom UTMs captured!');
refreshUTMs();
}
};
window.updateLinks = function() {
const baseURL1 = 'https://example.com/signup';
const baseURL2 = 'https://example.com/pricing';
document.getElementById('demo-link-1').href = appendToURL(baseURL1);
document.getElementById('demo-link-1').textContent = appendToURL(baseURL1);
document.getElementById('demo-link-2').href = appendToURL(baseURL2);
document.getElementById('demo-link-2').textContent = appendToURL(baseURL2);
};
window.setFirstTouch = function() {
getInstance().setMode('first-touch');
document.getElementById('current-mode').textContent = 'first-touch';
alert('Mode changed to first-touch');
};
window.setLastTouch = function() {
getInstance().setMode('last-touch');
document.getElementById('current-mode').textContent = 'last-touch';
alert('Mode changed to last-touch');
};
// Display current URL
document.getElementById('current-url').textContent = window.location.href;
// Initial refresh
window.refreshUTMs();
window.updateLinks();
console.log('✅ tiny-utm-keeper demo loaded!');
console.log('💡 Try adding UTM parameters to the URL and see them captured.');
console.log('📊 Current stored UTMs:', getUTMs());
</script>
</body>
</html>