PageSourceSearch

https://www.lizieradelac.ro/wp-content/plugins/themarketer-events-tracker/assets/js/tracking.js?ver=1791463096

js lizieradelac.ro collected 2026-10-08 12:39:04 UTC 5,763 bytes, 161 lines download raw bytes

1/**
2 * TheMarketer Events Tracker - Frontend JavaScript
3 */
4(function($) {
5    'use strict';
6
7    // Initialize dataLayer if it doesn't exist
8    window.dataLayer = window.dataLayer || [];
9
10    // Initialize tracking
11    function initTracking() {
12        // Track contact button clicks
13        // trackContactButtonClicks();
14        
15        // Track "Despre" tab on homepage
16        // trackDespreTab();
17        
18        // Track form submissions for email capture
19        trackFormSubmissions();
20    }
21
22    // Track clicks on contact buttons
23    function trackContactButtonClicks() {
24        // Adjust these selectors based on your theme's actual structure
25        $('a[href*="contact"], .contact-button, .btn-contact').on('click', function(e) {
26            sendEvent('clicked_contact_button');
27        });
28    }
29
30    // Track "Despre" tab on homepage
31    function trackDespreTab() {
32        // Adjust these selectors based on your theme's actual structure
33        $('.despre-tab, a[href="#despre"], [data-tab="despre"]').on('click', function(e) {
34            sendEvent('viewed_pagina_despre');
35        });
36    }
37
38    // Push __sm__set_email event to dataLayer
39    function pushSetEmailToDataLayer(email, data) {
40        data = data || {};
41        
42        // Validate email
43        if (!email || !isValidEmail(email)) {
44            console.warn('TheMarketer: Invalid email address');
45            return;
46        }
47        
48        // Prepare dataLayer event
49        var dataLayerEvent = {
50            event: '__sm__set_email',
51            email_address: email
52        };
53        
54        // Add optional fields if available
55        if (data.phone) {
56            dataLayerEvent.phone = data.phone;
57        }
58        if (data.firstname) {
59            dataLayerEvent.firstname = data.firstname;
60        }
61        if (data.lastname) {
62            dataLayerEvent.lastname = data.lastname;
63        }
64        
65        // Push to dataLayer
66        window.dataLayer.push(dataLayerEvent);
67        
68        console.log('TheMarketer: __sm__set_email pushed to dataLayer', dataLayerEvent);
69    }
70    
71    // Validate email format
72    function isValidEmail(email) {
73        var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
74        return emailRegex.test(email);
75    }
76    
77    // Track form submissions to capture email
78    function trackFormSubmissions() {
79        console.log('TheMarketer: Elementor form tracking initialized');
80        
81        // Track Elementor forms on submit_success event
82        $(document).on('submit_success', '.elementor-form', function(event, response) {
83            console.log('TheMarketer: Elementor submit_success event fired');
84            captureEmailFromForm($(this));
85        });
86    }
87    
88    // Capture email and other data from Elementor form
89    function captureEmailFromForm($form) {
90        console.log('TheMarketer: captureEmailFromForm called', $form);
91        
92        var email = '';
93        var data = {};
94        var formName = $form.attr('name');
95        
96        console.log('TheMarketer: Elementor form name:', formName);
97        
98        // Newsletter form - name="Newsletter"
99        if (formName === 'Newsletter') {
100            email = $form.find('input[name="form_fields[email_subscribe]"]').val();
101            data.phone = $form.find('input[name="form_fields[tel]"]').val();
102            data.firstname = $form.find('input[name="form_fields[field_5d99fde]"]').val(); // Prenume
103            data.lastname = $form.find('input[name="form_fields[field_abc3f8d]"]').val(); // Nume
104        }
105        // Contact form - name="Contact form"
106        else if (formName === 'Contact form') {
107            email = $form.find('input[name="form_fields[email]"]').val();
108            data.phone = $form.find('input[name="form_fields[phone]"]').val();
109            data.firstname = $form.find('input[name="form_fields[firstname]"]').val();
110            data.lastname = $form.find('input[name="form_fields[lastname]"]').val();
111        }
112        // Generic Elementor form fallback
113        else {
114            email = $form.find('input[type="email"]').first().val();
115            data.phone = $form.find('input[name="form_fields[phone]"], input[name="form_fields[tel]"]').first().val();
116            data.firstname = $form.find('input[name="form_fields[firstname]"]').first().val();
117            data.lastname = $form.find('input[name="form_fields[lastname]"]').first().val();
118        }
119        
120        // Push to dataLayer if email is found
121        console.log('TheMarketer: Extracted email:', email, 'data:', data);
122        
123        if (email && email.trim() !== '') {
124            pushSetEmailToDataLayer(email, data);
125        } else {
126            console.warn('TheMarketer: No valid email found in form');
127        }
128    }
129
130    // Send event to server via AJAX
131    function sendEvent(eventName, properties) {
132        properties = properties || {};
133        
134        $.ajax({
135            url: themarketerData.ajax_url,
136            type: 'POST',
137            data: {
138                action: 'themarketer_track_click',
139                nonce: themarketerData.nonce,
140                event: eventName,
141                properties: properties
142            },
143            success: function(response) {
144                if (window.console && window.console.log && themarketerData.debug) {
145                    console.log('TheMarketer event sent:', eventName, response);
146                }
147            },
148            error: function(xhr, status, error) {
149                if (window.console && window.console.error) {
150                    console.error('TheMarketer event error:', error);
151                }
152            }
153        });
154    }
155
156    // Initialize when document is ready
157    $(document).ready(function() {
158        initTracking();
159    });
160
161})(jQuery);

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.