我需要通过一个链接完成两件事

Posted

技术标签:

【中文标题】我需要通过一个链接完成两件事【英文标题】:I need two things to happen with one link 【发布时间】:2015-08-21 07:39:19 【问题描述】:

我有一个链接,它会打开一个弹出窗口,为您提供有关如何将此页面添加到您的书签的说明。现在,我还希望该链接在被点击时触发 Adwords 中的转换。为此,我有一个来自谷歌的脚本,我尝试将它与现有链接结合起来,但我认为我做错了,因为在我的测试中没有触发任何转换。请在这里帮助我:

<html>
<head>
 
</head>
<body>
 
<a id="bookmarkme" href="#" rel="sidebar" onClick="goog_report_conversion" title="bookmark this page">Bookmark this page!</a>
 
 
 
<!-- Google Code for People who added website to their bookmarks Conversion Page
In your html page, add the snippet and call
goog_report_conversion when someone clicks on the
chosen link or button. -->
<script type="text/javascript">
  /* <![CDATA[ */
 goog_snippet_vars = function() 
   var w = window;
   w.google_conversion_id = XXXXXXXX;
   w.google_conversion_label = "COldCKSHnl8Q2cu9ywM";
   w.google_remarketing_only = false;
 
 // DO NOT CHANGE THE CODE BELOW.
 goog_report_conversion = function(url) 
   goog_snippet_vars();
   window.google_conversion_format = "3";
   window.google_is_call = true;
   var opt = new Object();
   opt.onload_callback = function() 
   if (typeof(url) != 'undefined') 
     window.location = url;
   
 
 var conv_handler = window['google_trackConversion'];
 if (typeof(conv_handler) == 'function') 
   conv_handler(opt);
 

/* ]]> */
</script>
 
 
 
 
<script type="text/javascript">
    $(function() 
        $("#bookmarkme").click(function() 
            // Mozilla Firefox Bookmark
            if ('sidebar' in window && 'addPanel' in window.sidebar) 
               window.sidebar.addPanel(location.href,document.title,"");
             else if( /*@cc_on!@*/false)  // IE Favorite
                window.external.AddFavorite(location.href,document.title);
             else  // webkit - safari/chrome
                alert('Please press ' + (navigator.userAgent.toLowerCase().indexOf('mac') != - 1 ? 'Command/Cmd' : 'CTRL') + ' + D in order to add this page to your bookmarks, you can also use your browsers bookmark menu to do that.');
            
        );
    );
</script>
 
 
</body>
</html>

Setting up an onclick handler for conversions
First, make sure you selected Click instead of Page load from the "Tracking event" section of the "Advanced tag settings" in Part I of the instructions above. Your conversion tag should look like something this:

		<!-- Google Code for Add to Cart Conversion Page
		In your html page, add the snippet and call goog_report_conversion
		when someone clicks on the chosen link or button. -->
		<script type="text/javascript">
		  /* <![CDATA[ */
		  goog_snippet_vars = function() 
		    var w = window;
		    w.google_conversion_id = 12345678;
		    w.google_conversion_label = "abcDeFGHIJklmN0PQ";
		    w.google_conversion_value = 13.00;
		    w.google_conversion_currency = "USD";
		    w.google_remarketing_only = false;
		  
		  // DO NOT CHANGE THE CODE BELOW.
		  goog_report_conversion = function(url) 
		    goog_snippet_vars();
		    window.google_conversion_format = "3";
		    var opt = new Object();
		    opt.onload_callback = function() 
		    if (typeof(url) != 'undefined') 
		      window.location = url;
		    
		  
		  var conv_handler = window['google_trackConversion'];
		  if (typeof(conv_handler) == 'function') 
		    conv_handler(opt);
		  
		
		/* ]]> */
		</script>
		<script type="text/javascript"
		  src="//www.googleadservices.com/pagead/conversion_async.js">
		</script>
	
Now that you (or the person in charge of your website) have the conversion tracking tag, you're ready to paste. Here's how:

Go to the page on your website that shows the clickable button or link. Then open up the HTML code so you can edit it.
Find the body tags (<body></body>) of the page, then paste the code snippet you generated in AdWords between those two tags.
Adjust the HTML code to add the onclick handler. The particular onclick command you use will depend on how the link or button is displayed on your site: text link, image, or button.
Here's some sample code close up:

HTML before conversion tracking code (Sample only. Don't use in your website's code.)

	<html>
	<head>
	<title>Sample HTML File</title>
	</head>
	<body>
	This is the body of your web page.
	</body>
	</html>
	
Use the following command if the link is shown as:

 

a text link

	<body>
	<!-- Below is a sample link for a file download.
	You need to replace the URL for the file and the
	DOWNLOAD NOW text with the text you want to hyperlink. -->
	<a onclick="goog_report_conversion
		('http://www.example.com/whitepapers/a.pdf')"
		href="#" >DOWNLOAD NOW</a>
	</body>
	</html>
	
an image

	<!-- Below is a sample image for a file download.
	Replace download_button.gif with your
	button image and the document URL with your file's URL. -->
	<body>
	<img src="download_button.gif" 
		 
		onClick="goog_report_conversion
		('http://www..pdf')"/>
	</body>
	</html>
	
For the tracking to work, you'll need to make sure you include both the tag and the appropriate onclick tags from one of the examples above. This tells AdWords to record a conversion only when a customer clicks on a chosen link or button.

【问题讨论】:

截取的第二个代码是来自 google adwords 的说明。 您是否尝试将google_report_conversion() 添加到您使用jquery 设置的onclick 方法的开头?将其从链接标记中删除并将其放入方法中,然后看看会发生什么! 【参考方案1】:

好的,它的工作方式如下:

<a onclick="goog_report_conversion
		('')" id="bookmarkme" href="#" rel="sidebar"  title="bookmark this page">Bookmark this page!</a>

【讨论】:

以上是关于我需要通过一个链接完成两件事的主要内容,如果未能解决你的问题,请参考以下文章

在配置完 Exchange Server 2010 CAS Array后需要做的两件事

在提交时发生了两件事

如何让 C++ 程序同时做两件事?

jQuery:可拖动以下行:视觉“链接这两件事”指示器

在 PHP 中缓存动态图像

两件事