无法实现javascript跟踪功能

时间:2014-07-24 16:52:22

标签: javascript wordpress

我正在为当地企业开设网站。它们包含一个javascript文件,用于跟踪用户来自何处,并更改电话号码,横幅和隐藏的表单字段以进行广告系列跟踪。 我的问题是我无法让它发挥作用。

这是有问题的js。

    var myContactNum  = "";
    var myBannerImage = "";
    var myFriendlyCampaignName ="";
    var campaignInfoSource="";

    var utm_source = "";        

    function campaignInformationLookup(campaignName) {
        switch(campaignName) {

            case "fbgen" :
                myFriendlyCampaignName = "Facebook - Generic Campaign";
                myContactNum = "1-888-980-8550";
                myBannerImage = "http://www.eyetechlasik.com/images/stories/website_header_lasik_8550.jpg";
                utm_source = campaignName;
                break;

            case "drkadambi" :
                myFriendlyCampaignName = "Reputation - Dr. K";
                myContactNum = "1-888-980-8551";
                myBannerImage = "http://www.eyetechlasik.com/images/stories/website_header_lasik_8551.jpg";
                utm_source = campaignName;
                break;
            case "lbv" :
                myFriendlyCampaignName = "Reputation - LBV";
                myContactNum = "1-888-980-8552";
                myBannerImage = "http://www.eyetechlasik.com/images/stories/website_header_lasik_8552.jpg";
                utm_source = campaignName;
                break;

            case "googlesearch":
                myFriendlyCampaignName = "Google Ad - Search Results";
                myContactNum = "1-888-980-8554";
                myBannerImage = "http://www.eyetechlasik.com/images/stories/website_header_lasik_8554.jpg";
                utm_source = campaignName;
                break;

            case "default":
                myFriendlyCampaignName = "Organic - Reached Site without Ad";
                myContactNum = "1-866-808-3937";
                myBannerImage = "http://www.eyetechlasik.com/images/stories/website_header_lasik.jpg";
                utm_source = "default";             
                break;
            default:
                myFriendlyCampaignName = "Organic - Reached Site without Ad";
                myContactNum = "1-866-808-3937";
                myBannerImage = "http://www.eyetechlasik.com/images/stories/website_header_lasik.jpg";
                utm_source = "default"; 
        }
        return utm_source;
    }       


    function getQueryString(name) {
        var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
        return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
    }

    function myCampaign() {
        var eyeTechCampaign = getCookie("eyeTechCampaign");

        if(eyeTechCampaign == null || eyeTechCampaign == "" || eyeTechCampaign == 'undefined') {
            myCampaignFromURL = getQueryString("utm_campaign");
            theCampaign = campaignInformationLookup(myCampaignFromURL);
            setCookie("eyeTechCampaign",myCampaignFromURL,180);
            campaignInfoSource = "URL";
        }
        else {              
            theCampaign = eyeTechCampaign;
            campaignInfoSource = "Cookie";
            theSource = campaignInformationLookup(theCampaign);
            //update the cookie to expire 180 days from now, essentially refreshing the campaign
            setCookie("eyeTechCampaign",theCampaign,180);

        }   
        displayContactInfo();   
    }

    function getCookie(c_name) {
        var i,x,y,ARRcookies=document.cookie.split(";");
        for (i=0;i<ARRcookies.length;i++) {
            x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
            y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
            x=x.replace(/^\s+|\s+$/g,"");
            if (x==c_name) {
                return unescape(y);
            }
        }
    }

    function setCookie(c_name,value,exdays) {
        var exdate=new Date();
        exdate.setDate(exdate.getDate() + exdays);
        var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
        document.cookie=c_name + "=" + c_value;
    }

    function destroyCookie() {
        //Debug purposes only
        setCookie("eyeTechCampaign",0,-1)
    }

    function displayContactInfo() {

        document.getElementById('headerBanner').src = myBannerImage;
        document.getElementById('footerPhoneNum').innerHTML = myContactNum;

        //Only for the contact us page
        if(document.getElementById('contactUsPhoneNum') !='undefined') {
            document.getElementById('contactUsPhoneNum').innerHTML = myContactNum;
        }

        document.getElementById('OnlineCampaignSource').value = myFriendlyCampaignName;


    }

如果我尝试做一些简单的事情,比如document.write(myContactNum),我什么都没得到。如果我为myContactNum ex ..输入我自己的价值。

  var myContactNum = "1-800-555-5555";

我会得到那个价值。这让我相信这个功能本身就什么都不做。我试过在代码的不同部分调用函数,但仍然没有。有什么建议吗?

0 个答案:

没有答案