简体   繁体   English

alert()/ datalayer.push是不同的

[英]alert()/datalayer.push are different

I'm not very experienced so hopefully this is an easy question for one of you. 我不是很有经验,所以希望对您一个人来说这是一个简单的问题。 I'm using google tag manager to track any time a span element is opened or closed on a word press site(or trying to at least). 我正在使用Google Tag Manager来跟踪在wordpress网站上打开或关闭span元素的任何时间(或至少尝试这样做)。 This is the relevant code and the problem. 这是相关的代码和问题。

<script type="text/javascript">

  dataLayer.push({
            eventAction: text
             });

   var text = jQuery('span').click(function(){
     var t = jQuery(this).text();
     alert(JSON.stringify(t));
   });
</script>

This is triggered by any click that contains ac_title_class. 这是由包含ac_title_class的任何单击触发的。

the html class im targeting follows html类即时通讯定位如下

<span class="ac_title_class">
                            Purpose                         </span>

The problem is that this code send [object object] to google analytics instead of sending what the alert message says which is "/t/t/t/t/t/t/ Purpose /t/t/t/t/t"(that inst exactly what it says but close). 问题在于此代码将[对象对象]发送到Google Analytics(分析),而不是发送警报消息中所说的“ / t / t / t / t / t / t /目的/ t / t / t / t / t” (即表示完全正确,但关闭)。 I have tried countless different approaches and cant seem to figure it out. 我尝试了无数种不同的方法,但似乎无法弄清楚。 I greatly appreciate the help in advance. 我非常感谢提前提供的帮助。 Note: "ac_title_class" is part of a plugin. 注意:“ ac_title_class”是插件的一部分。

You can push the data layer with your data by passing variable name and its value for eg. 您可以通过传递变量名称及其值(例如)来使用数据推送数据层。 dataLayer.push({'variable_name': 'variable_value'});

For now you check my code below 现在您在下面检查我的代码

<script type="text/javascript">
var text = jQuery('span.ac_title_class').click(function(){
    var t = jQuery(this).text();
    dataLayer.push({eventAction: t });
});
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM