javascript - Omniture 跟踪和 jQuery

标签 javascript jquery html adobe-analytics

我一直在创建一些网站,这些网站的内容是通过调用 #div 容器的 jQuery 和 CSS 提取的。有谁知道在创建这些类型的单页网站时使用 Omniture Site Catalyst 跟踪代码的方法吗?可能的?

以前,我通过插入软件提供的以下难以辨认的代码块,将 Omniture 与更传统的 html 站点结合使用。在这种情况下,它似乎可以跟踪所有 .html 页面。

       <!-- SiteCatalyst Code version: H.17.
Copyright 1997-2008 Omniture, Inc. More info available at
http://www.omniture.com -->
<script language="JavaScript" type="text/javascript" src="http://www.urlofsite.com/js/s_code.js"></script>
<script language="JavaScript" type="text/javascript"><!--
/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
var s_code=s.t();if(s_code)document.write(s_code)//--></script>
<script language="JavaScript" type="text/javascript"><!--
if(navigator.appVersion.indexOf('MSIE')>=0)document.write(unescape('%3C')+'\!-'+'-')
//--></script><noscript><a href="http://www.omniture.com" title="Web Analytics"><img
src="http://code.urlofsite.com/b/ss/ranhrollup/1/H.17--NS/0"
height="1" width="1" border="0" alt="" /></a></noscript><!--/DO NOT REMOVE/-->

<!-- End SiteCatalyst code version: H.17. -->
</body>
</html>

有没有办法打破它,并创建几行带有 if 语句的 Javascript,将跟踪代码应用于特定的 #div#

更新:

我与一位专家谈过,他说您可以在 onClick 事件中添加额外的 s.t() 调用,以作为额外的页面 View 来跟踪任何您想要跟踪的内容。例如,您为“图书”链接设置了以下单击事件处理程序

$('a.manned-flight').click(function() {
  $('html, body').animate({
  scrollTop: 1250
}, 1000, function() {
  parallaxScroll(); // Callback is required for iOS
});
  return false;
});

您可以向此函数添加跟踪代码以指定不同的 pageName 并发送额外的页面 View 图像请求,如下所示:

$('a.manned-flight').click(function() {
  s.pageName = "www.urlofwebsite.com:Books";
  s.t();
  $('html, body').animate({
    scrollTop: 1250
  }, 1000, function() {
    parallaxScroll(); // Callback is required for iOS
  });
  return false;
});

但是考虑到站点有多大以及我必须定义多少内容区域,这似乎是一种不切实际的方法,而且在代码方面有些笨拙。有没有办法用 Javascript 数组来做到这一点?

最佳答案

很久以前,我不得不为 Web CMS 系统设置 Omniture 的分析工具,特别是我们公司的产品和购物车组件。该代码包含在我们网站模板的每个页面上(即包含文件)。假设您的网站不是完全静态的网站,您也可以这样做,将代码放入您的 .js 文件、模板、包含文件、母版页、 View (无论您可能使用何种方法在网站范围内重用)。如果我没记错的话,Omniture 坚持要将它的代码完全放在结束的 body 标签之前。代码就位后,编写一些 javascript 来为特定变量赋值,以用于在 Omniture 代码中设置适当的值。例如,如果您的页面偶然创建了一个漂亮的 SEO 标题,您可以从标题中提取值以用作 Omniture 页面名称。这只是一个例子。

另一方面,如果您的网站是静态网站,您的选择就不那么容易了。如果你能控制你的 div 的生成方式,你会过得更好。我的意思是,如果您可以以常规方式将数据返回给您的 div,则可以使用 javascript 或您最喜欢的 javascript 库(例如 jQuery)为您的 Omniture 变量生成适当的信息。更进一步,如果您完全控制了 HTML 的生成方式,则可以添加一个特定的类来注意,就像您的 a.manned-flight 示例一样。但是,我会为所有类型的点击寻找更通用的东西。

就像我说的,如果您可以控制呈现的数据,那么从呈现的 HTML 中提取数据就会更容易。否则,将很难提供 Omniture 所需的有意义的信息。希望这会有所帮助。

这就是我对你的问题的有限理解的想法。假设您的数据采用标准格式,如下例所示。

<div class="product-item">
    <input class='item-title' type='hidden' value='Book Title #1 Specific Page Name'/>
    <input class='other-stuff-for-analytics' type='hidden' value='More stuff here'/>
    <h3>Book Title #1</h3>
    <p>Description of Book Title #1 and some junk...</p>
</div>
<div class="product-item">
    <input class='item-title' type='hidden' value='Book Title #2 Specific Page Name'/>
    <input class='other-stuff-for-analytics' type='hidden' value='More stuff here'/>
    <h3>Book Title #2</h3>
    <p>Description of Book Title #2 and some junk...</p>
</div>
<div class="product-item">
    <input class='item-title' type='hidden' value='Book Title #3 Specific Page Name'/>
    <input class='other-stuff-for-analytics' type='hidden' value='More stuff here'/>
    <h3>Book Title #3</h3>
    <p>Description of Book Title #3 and some junk...</p>
</div>

<!-- The code below could be in your template/include file/master page/view/ .js file -->
<script>
    $('div.product-item').click(function () {
        var analyticsPageName = "";
        /* Possibly pull the value from hidden input  */
        analyticsPageName = $(this).children('input.item-title').val();

        /* OR Pull the information from the block of HTML that has the page title */
        analyticsPageName = $(this).children('h3').text();

        // ---OR---
        //whatever else you need to do to scrape your HTML
        //to get the information to plug into a variable

        s.pageName = analyticsPageName;
        s.t();
        $('html, body').animate({
            scrollTop: 1250
        }, 1000, function () {
            parallaxScroll(); // Callback is required for iOS
        });
        return false;
    });
</script>

关于javascript - Omniture 跟踪和 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8169265/

相关文章:

javascript - 基于 CheckBox 启用或禁用按钮

javascript - 有没有一种方法可以使用 Javascript 或 jQuery 来启动 Chrome Find? (与 ctrl + f 相同)?

javascript - 在网页上拖动滚动

javascript - 如何防止网站中笨拙的文本选择行为

javascript - 使用 Nodejs 的实时通知 Web 应用程序

javascript - 如何在 vue 组件的 google map 中显示组合框的选定城市?

javascript - 过滤掉node_modules中组件引起的React警告

javascript - 编写打乱函数的更简单方法

javascript - 在参数中声明数组是一种不好的做法吗?

c# - 没有模型和 Ajax 的 POST Json