Google标记管理工具 - CSS选择器挑战 [英] Google Tag Manager - CSS selector challenge

查看:240
本文介绍了Google标记管理工具 - CSS选择器挑战的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获取源代码中的链接的网址。挑战是URL被隐藏在图像后面,因此只让我获取图像url。

I am trying to get the URL of a link in the source code. The challenge is that the URL is hidden behind a image, and thus only letting me fetch the image-url.

我一直在尝试通过在触发器系统中使用新的CSS选择器来设法解决这个问题,并且创建一个DOM变量,图像被点击。

I've been trying to figure a way to solve this issue by using the new CSS selector in the trigger system and also made a DOM variable that should get the URL when the image is clicked. There can also be multiple downloads.

这里是我想要实现的示例:

Here is an example of what I am trying to achieve:

<div> 
 <div class="download">
  <a href="example.com/The-URL-I-Want-to-get-if-top-image-is-clicked.pdf" target="_blank">
   <img src="some-download-image.png"/></a>
 <div class="download">
  <a href="example.com/Another-URL-I-Want-to-get-if-middle-image-is-clicked.pdf" target="_blank">
   <img src="some-download-image.png"/></a>
 <div class="download">
  <a href="example.com/Last-URL-I-Want-to-get-if-bottom-image-is-clicked.pdf" target="_blank">
   <img src="some-download-image.png"/></a>
 </div>
</div>

此代码段上面和下面有很多代码,但是使用选择器应该是相当容易得到我想要的信息。只有我不这样做。

There are much code above and below this snippet, but with the selector it should be fairly easy to get the information I want. Only that I don't.

如果有人遇到这个墙并解决了,我真的想知道如何。 :)

If anyone have met this wall and solved it, I really would like to know how. :)

推荐答案

这是一个可能的解决方案。根据我的理解,当您点击下载图片时,您希望抓取锚点元素的href属性。

This is one possible solution. So as I understand it, you would like to grab the anchor element's href attribute when you click the "download" image.

需要创建自定义JavaScript变量您可以操纵点击元素对象:

A Custom Javascript variable would need to be created so that you can manipulate the click element object:

function(){
   var ec = {{Click Element}};
   var href = $(ec).closest('a').attr('href');
   return href;
}

因此,您需要进行尽职调查,东西,但基本上这应该返回你的href,然后你将需要解析字符串来提取你需要的部分。

So you will need to do your due diligence and add in your error checking and stuff, but basically this should return to you the href, and then you will need to parse the string to extract the portion that you need.

这篇关于Google标记管理工具 - CSS选择器挑战的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆