-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchResult
51 lines (40 loc) · 1.27 KB
/
searchResult
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
cHTML custom arry listener
<script>
// Custom JavaScript code
function trackButtonClick(event) {
var resultItem = event.target.closest('.resultItem');
var titleValue = resultItem.querySelector('.resultTitle').textContent;
// Send article data to Google Tag Manager
dataLayer.push({
'event': 'articleClicked',
'articleTitle': titleValue,
'articleContent': contentValue
// Add any additional data you want to track
});
}
// Attach event listener to all result buttons
var resultButtons = document.querySelectorAll('.resultButton');
resultButtons.forEach(function(button) {
button.addEventListener('click', trackButtonClick);
});
</script>
======structure=======
<!-- Search results -->
<div class="searchResults">
<div class="resultItem">
<h3 class="resultTitle">Article 1</h3>
<p>Content 1</p>
<img src="article1.jpg" alt="Article 1" />
<button class="resultButton">Track</button>
</div>
<div class="resultItem">
<h3 class="resultTitle">Article 2</h3>
<p>Content 2</p>
<img src="article2.jpg" alt="Article 2" />
<button class="resultButton">Track</button>
</div>
<!-- Add more result items as needed -->
</div>
if you smart You you know that what is that how to use
any help contact us
https://wlo.link/@trackingbygtm