Answer the question
In order to leave comments, you need to log in
The goal is triggered when the page is loaded, but should only be triggered when the button is clicked, how to fix it?
The site uses a script to hide part of the phone number and display it only by clicking on the text "Show". Through GTM, it is configured that when you click on the element class of the "Show" (class "sh_nmr"), an event is sent and the goal is triggered in Google Analytics.
But the problem is that the goal is triggered not only on click, but also just when the page is loaded. Apparently the script is written like this. How can this be fixed? The only option that comes to my mind is with a time limit on the target, i.e. during the first 10 seconds after loading the page, do not count the goal, is it possible to implement this in GTM?
The script itself:
<script>
jQuery(document).ready(function($){
$.fn.textToggle = function(cls, str) {
return this.each(function(i) {
$(this).click(function() {
var c = 0, el = $(cls).eq(i), arr = [str,el.text()];
return function() {
el.text(arr[c++ % arr.length]);
}}());
})};
$(function(){
$('.sh_nmr').textToggle(".sh_nmr","").click();
$('.sh_nmr').textToggle(".num_hide","ХХ ХХ").click();
});
});
</script>
<a href="tel:+74991137011">7 499 113 <span class="num_hide">70 11</span></a>
<span class="sh_nmr">ПОКАЗАТЬ</span>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question