File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
code-snippets/event-snippets Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Plugin Name: Koko Analytics: Track UTM Parameters
5+ *
6+ * Requires 3 events named "UTM Source", "UTM Medium" and "UTM Campaign"
7+ */
8+
9+ add_action ('wp_footer ' , function () {
10+ ?> <script>
11+ window.addEventListener('load', function() {
12+ let map = {
13+ 'utm_source': 'UTM Source',
14+ 'utm_medium': 'UTM Medium',
15+ 'utm_campaign': 'UTM Campaign',
16+ };
17+
18+ let queryParams = new URLSearchParams(window.location.search);
19+ let hashParams = new URLSearchParams(window.location.hash.substring(1));
20+ for (let [p, eventName] of Object.entries(map)) {
21+ let value = queryParams.get(p) ?? hashParams.get(p);
22+ if (value) {
23+ window.koko_analytics.trackEvent(eventName, value);
24+ }
25+ }
26+ });
27+ </script><?php
28+ });
You can’t perform that action at this time.
0 commit comments