PageSourceSearch

https://logomakr.com/ai-logo-generator/script.js

js logomakr.com collected 2026-09-24 08:36:16 UTC 6,125 bytes, 186 lines download raw bytes

1/**
2 * /ai-logo-generator/ — funnel source tracker (first-touch).
3 * Sets lm_funnel_src=ai-logo-generator cookie ONLY if not already set,
4 * so upstream attribution is preserved when user navigates further. Deployed 2026-06-05.
5 */
6(function () {
7  try {
8    if (!document.cookie.split('; ').some(function (c) { return c.indexOf('lm_funnel_src=') === 0; })) {
9      document.cookie = 'lm_funnel_src=ai-logo-generator; path=/; max-age=1800; samesite=lax; secure';
10    }
11  } catch (e) { /* non-fatal */ }
12})();
13
14/**
15 * /logo-maker-2/ — Logo Maker landing page
16 * Submits business name to /customize-logo/ with ?logoName= parameter
17 */
18
19(function () {
20  'use strict';
21
22  const form = document.getElementById('logoForm');
23  const input = document.getElementById('businessName');
24  const submitBtn = document.getElementById('submitBtn');
25  const message = document.getElementById('formMessage');
26  // Capture pristine button text so we can restore it after bfcache back-navigation.
27  const ORIGINAL_BTN_TEXT = submitBtn ? submitBtn.textContent : 'Generate My Logo';
28  const menuToggle = document.getElementById('menuToggle');
29  const mobileNav = document.getElementById('mobileNav');
30  const openContactBtn = document.getElementById('openContactPopup');
31  const openContactBtnMobile = document.getElementById('openContactPopupMobile');
32  const closeContactBtn = document.getElementById('closeContactPopup');
33  const contactPopup = document.getElementById('contactPopup');
34
35  // ============ Form submission ============
36  function handleSubmit(e) {
37    e.preventDefault();
38    const businessName = input.value.trim();
39
40    if (!businessName) {
41      message.textContent = 'Please enter your company name to continue.';
42      message.className = 'hero-helper error';
43      input.focus();
44      return;
45    }
46
47    if (businessName.length < 2) {
48      message.textContent = 'Please enter at least 2 characters.';
49      message.className = 'hero-helper error';
50      input.focus();
51      return;
52    }
53
54    submitBtn.disabled = true;
55    submitBtn.textContent = 'Creating...';
56    message.textContent = 'Taking you to logo customization...';
57    message.className = 'hero-helper success';
58
59    if (typeof gtag === 'function') {
60      gtag('event', 'logo_maker_form_submit', {
61        event_category: 'engagement',
62        event_label: 'ai-logo-generator',
63        business_name_length: businessName.length
64      });
65    }
66
67    if (window.dataLayer) {
68      window.dataLayer.push({
69        event: 'logo_maker_form_submit',
70        source_page: '/ai-logo-generator/',
71        business_name_provided: true
72      });
73    }
74
75    try {
76      sessionStorage.setItem('logomakr_business_name', businessName);
77      sessionStorage.setItem('logomakr_referrer', '/ai-logo-generator/');
78    } catch (err) { /* non-fatal */ }
79
80    const target = '/customize-logo/?logoName=' + encodeURIComponent(businessName);
81    window.location.href = target;
82  }
83
84  if (form) {
85    form.addEventListener('submit', handleSubmit);
86  }
87
88  // Fix for back-button restoring page in mid-submit "Creating..." state.
89  // When user submits, navigates to /customize-logo/, then clicks back,
90  // the browser bfcache restores the page with the button still disabled
91  // and the "Taking you to..." message visible. Reset everything on pageshow.
92  window.addEventListener('pageshow', function (event) {
93    if (submitBtn) {
94      submitBtn.disabled = false;
95      submitBtn.textContent = ORIGINAL_BTN_TEXT;
96    }
97    if (message) {
98      message.textContent = '';
99      message.className = 'hero-helper';
100    }
101    if (input) {
102      input.value = '';
103    }
104  });
105
106  if (input) {
107    input.addEventListener('input', function () {
108      if (message.className.includes('error')) {
109        message.textContent = '';
110        message.className = 'hero-helper';
111      }
112    });
113
114    input.addEventListener('keypress', function (e) {
115      if (e.key === 'Enter') {
116        e.preventDefault();
117        handleSubmit(e);
118      }
119    });
120  }
121
122  // ============ Focus input from any CTA button ============
123  document.querySelectorAll('[data-focus-input]').forEach(function (el) {
124    el.addEventListener('click', function (e) {
125      e.preventDefault();
126      window.scrollTo({ top: 0, behavior: 'smooth' });
127      setTimeout(function () {
128        if (input) input.focus();
129      }, 600);
130    });
131  });
132
133  // ============ Mobile menu ============
134  if (menuToggle && mobileNav) {
135    menuToggle.addEventListener('click', function () {
136      const isOpen = mobileNav.classList.toggle('open');
137      menuToggle.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
138    });
139  }
140
141  // ============ Contact popup ============
142  function openContactPopup() {
143    if (contactPopup) {
144      contactPopup.classList.add('open');
145      contactPopup.setAttribute('aria-hidden', 'false');
146      document.body.style.overflow = 'hidden';
147
148      if (typeof gtag === 'function') {
149        gtag('event', 'contact_popup_open', {
150          event_category: 'engagement',
151          event_label: 'ai-logo-generator'
152        });
153      }
154    }
155  }
156  function closeContactPopup() {
157    if (contactPopup) {
158      contactPopup.classList.remove('open');
159      contactPopup.setAttribute('aria-hidden', 'true');
160      document.body.style.overflow = '';
161    }
162  }
163
164  if (openContactBtn) openContactBtn.addEventListener('click', openContactPopup);
165  if (openContactBtnMobile) openContactBtnMobile.addEventListener('click', openContactPopup);
166  if (closeContactBtn) closeContactBtn.addEventListener('click', closeContactPopup);
167  if (contactPopup) {
168    contactPopup.addEventListener('click', function (e) {
169      if (e.target === contactPopup) closeContactPopup();
170    });
171  }
172  document.addEventListener('keydown', function (e) {
173    if (e.key === 'Escape' && contactPopup && contactPopup.classList.contains('open')) {
174      closeContactPopup();
175    }
176  });
177
178  // ============ GA4 page view ============
179  if (typeof gtag === 'function') {
180    gtag('event', 'page_view', {
181      page_title: document.title,
182      page_location: window.location.href,
183      page_path: '/ai-logo-generator/'
184    });
185  }
186})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.