/* * cmdatatagutils.js * * Coremetrics Tag v3.1, 2/28/2002 * COPYRIGHT 1999-2002 COREMETRICS, INC. * ALL RIGHTS RESERVED. U.S.PATENT PENDING * * The following functions aid in the creation of Coremetrics data tags. * */ // TAG GENERATING FUNCTIONS --------------------------------------------------- cm_ClientID = "90018751"; cm_TrackLink = "A"; cm_TrackImpressions = "S"; /* * Calling this function points tags to the production database */ function cmSetProduction(){ cm_HOST="data.coremetrics.com/eluminate?"; } /* * Creates a Tech Props tag. * pageID : required. Page ID to set on this Pageview tag */ function cmCreateTechPropsTag(pageID, categoryID) { if (pageID) { var cm=new _cm("tid", "6", "vn2", "e4.0"); cm.pc="Y"; cm.pi = pageID; cm.cg = categoryID; // if available, override the referrer with the frameset referrer if (parent.cm_ref != null) { cm.rf = parent.cm_ref; parent.cm_ref = document.URL; } cm.addTP(); cm.writeImg(); } } /* * Creates a Pageview tag with the given Page ID * * pageID : required. Page ID to set on this Pageview tag * searchString : optional. Internal search string enterred by user to reach * this page. * categoryID : optional. Category ID to set on this Pageview tag * * returns nothing, causes a document.write of an image request for this tag. */ function cmCreatePageviewTag(pageID, searchString, categoryID, numResults) { if (pageID == null) { pageID = getDefaultPageID(); } var cm = new _cm("tid", "1", "vn2", "e4.0"); if (pageID){ cm.pi = pageID; } if (numResults){ cm.sr = numResults; } if (searchString){ cm.se = searchString; } if (categoryID) { cm.cg = categoryID; } // if available, override the referrer with the frameset referrer if (parent.cm_ref != null) { cm.rf = parent.cm_ref; parent.cm_ref = document.URL; } cm.writeImg(); } /* * Creates a Pageview tag with the default value for Page ID. * Format of Page ID is "x/y/z/MyPage.asp" * * returns nothing, causes a document.write of an image request for this tag. */ function cmCreateDefaultPageviewTag() { cmCreatePageviewTag(getDefaultPageID(), null, null); } /* * Creates a Productview Tag * Also creates a Pageview Tag by setting pc="Y" * Format of Page ID is "PRODUCT: ()" * * productID : required. Product ID to set on this Productview tag * productName : required. Product Name to set on this Productview tag * categoryID : optional. Category ID to set on this Productview tag * * returns nothing, causes a document.write of an image request for this tag. */ function cmCreateProductviewTag(productID, productName, categoryID) { var cm = new _cm("tid", "5", "vn2", "e4.0"); if (productName == null) { productName = ""; } // if available, override the referrer with the frameset referrer if (parent.cm_ref != null) { cm.rf = parent.cm_ref; parent.cm_ref = document.URL; } cm.pr = productID; cm.pm = productName + " (" + productID + ")"; cm.cg = categoryID; cm.pc = "Y"; cm.pi = "PRODUCT: " + productName + " (" + productID + ")"; cm.writeImg(); } /* * Creates a Pageview tag appropriate for category pages. * Format of Page ID is "CATEGORY: () " * * categoryID : required. Category ID to set on this Pageview tag and in * the Page ID. * categoryName : required. Category Name to set on this Pageview tag and in * the Page ID. * pageNumber : optional. If appropriate, the current page number for this * category. Only page numbers greater than "1" will be * added to the Page ID. * * returns nothing, causes a document.write of an image request for this tag. */ function cmCreateCategoryPageviewTag(categoryID, categoryName, pageNumber) { if (categoryID && categoryName) { if (pageNumber && (pageNumber != "") && (pageNumber != "1")) { cmCreatePageviewTag("CATEGORY: " + categoryName + " (" + categoryID + ")" + " PAGE " + pageNumber, null, categoryID); } else { cmCreatePageviewTag("CATEGORY: " + removeHTML(categoryName) + " (" + categoryID + ")", null, categoryID); } } } /* * Creates a Pageview tag appropriate for category pages. * Format of Page ID is "SUB CATEGORY: () " * * categoryID : required. Category ID to set on this Pageview tag and in * the Page ID. * categoryName : required. Category Name to set on this Pageview tag and in * the Page ID. * pageNumber : optional. If appropriate, the current page number for this * category. Only page numbers greater than "1" will be * added to the Page ID. * * returns nothing, causes a document.write of an image request for this tag. */ function cmCreateSubCategoryPageviewTag(categoryID, categoryName, pageNumber) { if (categoryID && categoryName) { if (pageNumber && (pageNumber != "") && (pageNumber != "1")) { cmCreatePageviewTag("SUB CATEGORY: " + removeHTML(categoryName) + " (" + categoryID + ")" + " PAGE " + pageNumber, null, categoryID); } else { cmCreatePageviewTag("SUB CATEGORY: " + removeHTML(categoryName) + " (" + categoryID + ")", null, categoryID); } } } /* * Creates a Pageview tag appropriate for category pages. * Format of Page ID is "PROD LIST: () " * * categoryID : required. Category ID to set on this Pageview tag and in * the Page ID. * categoryName : required. Category Name to set on this Pageview tag and in * the Page ID. * pageNumber : optional. If appropriate, the current page number for this * category. Only page numbers greater than "1" will be * added to the Page ID. * * returns nothing, causes a document.write of an image request for this tag. */ function cmCreateProdlistPageviewTag(categoryID, categoryName, pageNumber) { if (categoryID && categoryName) { if (pageNumber && (pageNumber != "") && (pageNumber != "1")) { cmCreatePageviewTag("PROD LIST: " + removeHTML(categoryName) + " (" + categoryID + ")" + " PAGE " + pageNumber, null, categoryID); } else { cmCreatePageviewTag("PROD LIST: " + removeHTML(categoryName) + " (" + categoryID + ")", null, categoryID); } } } /* * Creates a Shop tag with Action 5 (Shopping Cart) * * productID : required. Product ID to set on this Shop tag * quantity : required. Quantity to set on this Shop tag * productPrice : required. Price of one unit of this product * categoryID : optional. Category to set on this Shop tag * * returns nothing, causes a document.write of an image request for this tag. */ function cmCreateShopAction5Tag(productID, productName, productQuantity, productPrice, categoryID){ var cm = new _cm("tid", "4", "vn2", "e4.0"); cm.at = "5"; cm.pr = productID; cm.pm = productName + " (" + productID + ")"; cm.qt = productQuantity; cm.bp = trimCurrency(productPrice); if (categoryID) { cm.cg = categoryID; } cm.writeImg(); } /* * Creates a Shop tag with Action 9 (Order Receipt / Confirmed) * * productID : required. Product ID to set on this Shop tag * productName : required. Product Name to set on this Shop tag * quantity : required. Quantity to set on this Shop tag * productPrice : required. Price of one unit of this product * customerID : required. ID of customer making the purchase * orderID : required. ID of order this lineitem belongs to * orderTotal : required. Total price of order this lineitem belongs to * categoryID : optional. Category to set on this Shop tag * * returns nothing, causes a document.write of an image request for this tag. */ function cmCreateShopAction9Tag(productID, productName, productQuantity, productPrice, customerID, orderID, orderTotal, categoryID) { var cm = new _cm("tid", "4", "vn2", "e4.0"); cm.at = "9"; cm.pr = productID; cm.qt = productQuantity; cm.pm = productName + " (" + productID + ")"; cm.bp = trimCurrency(productPrice); cm.cd = customerID; cm.on = orderID; cm.tr = trimCurrency(orderTotal); if (categoryID) { cm.cg = categoryID; } cm.writeImg(); } /* * Creates an Order tag * * orderID : required. Order ID of this order * orderTotal : required. Total of this order (minus tax and shipping) * orderSKUData : required. String representation of all lineitems * orderShipping : required. Shipping charge for this order * customerID : required. Customer ID that placed this order * customerCity : optional. City of Customer that placed this order * customerState : optional. State of Customer that placed this order * customerZIP : optional. Zipcode of Customer that placed this order * * returns nothing, causes a document.write of an image request for this tag. */ function cmCreateOrderTag(orderID, orderTotal, orderSKUData, orderShipping, customerID, customerCity, customerState, customerZIP) { var cm = new _cm("tid", "3", "vn2", "e4.0"); cm.on = orderID; cm.tr = trimCurrency(orderTotal); cm.osk = orderSKUData; cm.sg = trimCurrency(orderShipping); cm.cd = customerID; cm.sa = customerState; cm.ct = customerCity; cm.zp = customerZIP; cm.writeImg(); } /* * Creates a Registration tag and/or a Newsletter tag * * customerID : required for Registration. ID of Customer to register. * customerEmail : required for Newsletters. Optional for Registration. * customerCity : optional. City of Customer that placed this order * customerState : optional. State of Customer that placed this order * customerZIP : optional. Zipcode of Customer that placed this order * newsletterName : required for Newsletters. The name of the Newsletter. * subscribe : required for Newsletters. Either "Y" or "N" * * returns nothing, causes a document.write of an image request for this tag. */ function cmCreateRegistrationTag( customerID, customerEmail, customerCity, customerState, customerZIP, newsletterName, subscribe) { var cm = new _cm("tid", "2", "vn2", "e4.0"); cm.cd = customerID; cm.em = customerEmail; cm.sa = customerState; cm.ct = customerCity; cm.zp = customerZIP; if (newsletterName && subscribe) { cm.nl = newsletterName; cm.sd = subscribe; } // Makes this tag act like a page view. Make sure there are NO OTHER // page view tags on a page. cm.pi = getDefaultPageID(); cm.pc="Y"; cm.writeImg(); } /* Creates an Error Tag * * returns nothing, causes a document.write of an image request for this tag. */ function cmCreateErrorTag(ErrorPage) { var cm=new _cm("tid", "404", "vn2", "e4.0"); //DO NOT CHANGE THESE PARAMETERS // get the referrer from the frameset if (parent.cm_ref != null) { cm.rf = parent.cm_ref; parent.cm_ref = document.URL; } cm.pc = "Y"; // Remove any periods from ErrorPage cm.pi = ErrorPage.replace(".",""); cm.writeImg(); } // HELPER FUNCTIONS ----------------------------------------------------------- /* These functions are used by the tag-generating functions and/or may be used * in in general as convenience functions */ /* * Creates an acceptable default Page ID value to use for Pageview tags. * The default Page ID is based on the URL, and consists of the path and * filename (without the protocol, domain and query string). * * example: * returns "x/y/MyPage.asp" for the URL http://www.mysite.com/x/y/MyPage.asp */ function getDefaultPageID() { var pageName = window.location.pathname; // eliminates everything after "?" (for Opera browswers) var tempIndex1 = pageName.indexOf("?"); if (tempIndex1 != -1) { pageName = pageName.substr(0, tempIndex1); } // eliminates everything after "#" (for Opera browswers) var tempIndex2 = pageName.indexOf("#"); if (tempIndex2 != -1) { pageName = pageName.substr(0, tempIndex2); } // eliminates everything after ";" var tempIndex3 = pageName.indexOf(";"); if (tempIndex3 != -1) { pageName = pageName.substr(0, tempIndex3); } var slashPos = pageName.lastIndexOf("/"); if (slashPos == pageName.length - 1) { pageName = pageName + "index.jsp"; /****************** SET TO DEFAULT DOC NAME */ } while (pageName.indexOf("/") == 0) { pageName = pageName.substr(1,pageName.length); } // Bombay only pageName = pageName.replace("webapp/wcs/stores/servlet/",""); pageName = cleanWebSphereView(pageName); return(pageName); } function trimCurrency(dollarValue) { var decimalPos = dollarValue.indexOf("."); if (dollarValue.substr(decimalPos,dollarValue.length-decimalPos-1).length>2) { dollarValue= dollarValue.substr(0,decimalPos+3); } return dollarValue.replace("$",""); } function cleanWebSphereView(pageName) { // First, find all occurrences of lower-case letters // followed by upper-case ones and place a space // in between re=/(\w+)([a-z])([A-Z])(\w+)/; while (pageName.search(re) != -1) { pageName = pageName.replace(re,"$1$2 $3$4"); } // Finally, remove the string " View" from the page name return pageName.replace(" View",""); } function removeHTML(theString) { re = /(\w*)(<[^<>]*>)(\w*)/; return replaceAllOccurrences(theString,re,"$1$3"); } function replaceAllOccurrences(str, regExpression, replExpression) { while (str.search(regExpression) != -1) { //alert(str); str = str.replace(regExpression,replExpression); } return str; } if (defaultNormalize == null) { var defaultNormalize = null; } /* This normalization function takes a list of parameters and parses out all url parameters that ARE in that list. This only handles the simple case of basic url parameters in the query string. */ function myNormalizeURL(url, isHref) { var newURL = url; if (isHref) { var questMarkIndex = newURL.indexOf("?"); var endParamString = newURL.substring(questMarkIndex, newURL.length); var tempQuestString = newURL.substring(0, questMarkIndex-1); if (questMarkIndex != -1) { var firstHyphen = tempQuestString.indexOf("-"); if (firstHyphen != -1) { var hyphenString = tempQuestString.substring(firstHyphen + 1, tempQuestString.length); var secondHyphen = hyphenString.indexOf("-"); var backSlashString = tempQuestString.substring(0, firstHyphen - 1); var backSlash = backSlashString.indexOf("/"); if (secondHyphen == 7 && hyphenString.length == 14 && (backSlash = backSlashString.length - 4)) { var beginString = tempQuestString.substring(0, questMarkIndex-20); newURL = beginString + endParamString; } } } else if (questMarkIndex == -1) { var firstHyphen2 = newURL.indexOf("-"); if (firstHyphen2 != -1) { var hyphenString2 = newURL.substring(firstHyphen2 + 1, newURL.length); var secondHyphen2 = hyphenString2.indexOf("-"); var backSlashString2 = newURL.substring(0, firstHyphen2 - 1); var backSlash2 = backSlashString2.indexOf("/"); if (secondHyphen2 == 7 && hyphenString2.length == 15 && (backSlash2 = backSlashString2.length - 4)) { var beginString2 = newURL.substring(0, newURL.length-20); newURL = beginString2; } } } if (defaultNormalize != null) { newURL = defaultNormalize(newURL, isHref); } } return newURL; } // install normalization if (document.cmTagCtl != null) { var func = "" + document.cmTagCtl.normalizeURL; if (func.indexOf('myNormalizeURL') == -1) { defaultNormalize = document.cmTagCtl.normalizeURL; document.cmTagCtl.normalizeURL = myNormalizeURL; } } //-->