Export (0) Print
Expand All

Campaign Analytics Scripts

When you define a Campaign Analytics goal and corresponding steps, a script is generated for each specified step of the goal. To get the script for each step of a goal, call the GetGoals operation and locate the Goal object of interest (either by name or ID). Access the Steps element of the goal object and get each step. Access the Script element of the Step object to get the script to use on a web page of your website.

Ideally when you added the steps to the goal, you used a naming convention so that you can easily associate a step with a web page. Depending on the number and types of steps, you can also use the Type and PositionNumber elements of the Step object to associate a step with a web page of your website.

For details about where to place the script on your web page, see Placing the Script on your web page.

You do not need to alter the scripts for the landing page, browse pages, and prospect pages. However, for the conversion script, you may need to update the script depending on the revenue model that you use (fixed or variable) and whether you capture cost data, such as sales tax and shipping fees, in the conversion data.

System_CLiX_note Note

Revenue and costs are not tracked for Land, Browse, or Prospect steps. If you specify such values in steps other than a Conversion step they will be ignored by Bing Ads.

For details about changes that you might need to make to your revenue conversion script, see the following sections:

For information about how to specify whether the script counts one conversion per click or multiple conversions per click, see Setting the dedup Parameter.

For a list of issues to avoid, see Issues to Avoid.

For troubleshooting tips, see Troubleshooting Published Scripts.

Placing the Script on your web page

Place the following elements of the script in the <body> section of the web page near the closing tag.

<script type="text/javascript">
    if (!window.mstag) mstag = { loadTag: function () { }, time: (new Date()).getTime() };
</script>

<script id="mstag_tops" type="text/javascript" 
    src="//flex.msn.com/mstag/site/<Bing Ads-defined GUID Goes Here>/mstag.js">
</script>

<script type="text/javascript">
    mstag.loadTag(
        "analytics", 
        { dedup: "1", domainId: "XXXXXX", type: "1", revenue: "<REVENUEVALUEGOESHERE>", actionid: "XXXX" }
        )
</script>

<noscript>
    <iframe src="//flex.msn.com/mstag/tag/<Bing Ads-defined GUID Goes Here>/analytics.html?dedup=1&domainId=XXXXXX&type=1&revenue=&actionid=XXXX"
            frameborder="0" scrolling="no" width="1" height="1" style="visibility: hidden; display: none">
    </iframe>
</noscript>

The following two elements from the above code send the information to Bing Ads. The browser determines whether the <script> or <noscript> code sends the information. If the browser supports JavaScript, the <script> element sends the data; otherwise, the <noscript> element sends the data.

<script type="text/javascript">
    mstag.loadTag(
        "analytics", 
        { dedup: "1", domainId: "XXXXXX", type: "1", revenue: "<REVENUEVALUEGOESHERE>", actionid: "XXXX" }
        )
</script>

<noscript>
    <iframe src="//flex.msn.com/mstag/tag/<Bing Ads-defined GUID Goes Here>/analytics.html?dedup=1&domainId=XXXXXX&type=1&revenue=&actionid=XXXX"
            frameborder="0" scrolling="no" width="1" height="1" style="visibility: hidden; display: none">
    </iframe>
</noscript>

A web page can contain the analytics scripts from only one account. If the account defines multiple goals, the web page can contain the scripts of one or more of the goals. However, the web page must include only one occurrence of the following script elements that you copy from the script of one of the goals.

<script type="text/javascript">
    if (!window.mstag) mstag = { loadTag: function () { }, time: (new Date()).getTime() };
</script>

<script id="mstag_tops" type="text/javascript" 
    src="//flex.msn.com/mstag/site/<Bing Ads-defined GUID Goes Here>/mstag.js">
</script>

Fixed Revenue Model

The following shows an example of a script for a conversion step that uses the fixed revenue model. The generated script does not include the revenue parameter in the loadTag call. You must include the revenue parameter and specify its fixed value. The example shows only the script elements that you place in the <body> section of your web page. For more information, see Placing the Script on your web page.


<script type="text/javascript">
    mstag.loadTag(
        "analytics", 
        { dedup: "1", domainId: "XXXXXX", type: "1", revenue: "<REVENUEVALUEGOESHERE>", actionid: "XXXX" }
        )
</script>

<noscript>
    <iframe src="//flex.msn.com/mstag/tag/<Bing Ads-defined GUID Goes Here>/analytics.html?dedup=1&domainId=XXXXXX&type=1&revenue=<REVENUEVALUEGOESHERE>&actionid=XXXX"
            frameborder="0" scrolling="no" width="1" height="1" style="visibility: hidden; display: none">
    </iframe>
</noscript>

Variable Revenue Model

The following shows an example of a script for a conversion step that uses the variable revenue model. You must add a JavaScript function or script variable that provides the revenue value for the conversion. This example uses a function named getRevenue to provide the revenue value.

For the <noscript> element, the server that serves the web page will need to dynamically generate the source URL in order to include the revenue value before loading the page.

The example shows only the script elements that you place in the <body> section of your web page (see Placing the Script on your web page).

<script type="text/javascript">
    // An example function that returns
    // the revenue value for the conversion.
    
    function getRevenue() {
        // Replace the content of this function with your own code
        // that returns the revenue value.
        
        return Math.ceil(Math.random() * 10);
    }
</script>

<script type="text/javascript">
    mstag.loadTag(
        "analytics", 
        { dedup: "1", domainId: "XXXXXX", type: "1", revenue: getRevenue(), actionid: "XXXX" }
        )
</script>

<noscript>
    <iframe src="//flex.msn.com/mstag/tag/<Bing Ads-defined GUID Goes Here>/analytics.html?dedup=1&domainId=XXXXXX&type=1&revenue=&actionid=XXXX"
            frameborder="0" scrolling="no" width="1" height="1" style="visibility: hidden; display: none">
    </iframe>
</noscript>

Including Costs in the Conversion Data

If you chose to capture costs—such as sales tax, shipping fees, or other costs—the script will include parameters for these cost items. You must update the script to specify the values of these cost items. If the costs are fixed, you can specify a constant value for each item. Otherwise, you must provide a function that returns the cost value.

The following example shows how to set the sales tax and shipping fees cost parameters when the values are fixed. The parameter name that is used to capture other costs is nonadvertisingcost. The example shows only the script elements that you place in the <body> section of your web page. For more information, see Placing the Script on your web page.


<script type="text/javascript">
    mstag.loadTag(
        "analytics", 
        { dedup: "1", domainId: "XXXXXX", type: "1", taxcost: "<SALESTAXVALUEGOESHERE>", shippingcost: "<SHIPPINGFEEVALUEGOESHERE>", revenue: "<REVENUEVALUEGOESHERE>", actionid: "XXXX" }
        )
</script>

<noscript>
    <iframe src="//flex.msn.com/mstag/tag/<Bing Ads-defined GUID Goes Here>/analytics.html?dedup=1&domainId=XXXXXX&type=1&taxcost=<SALESTAXVALUEGOESHERE>&shippingcost=<SHIPPINGFEEVALUEGOESHERE>&revenue=<REVENUEVALUEGOESHERE>&actionid=XXXX"
            frameborder="0" scrolling="no" width="1" height="1" style="visibility: hidden; display: none">
    </iframe>
</noscript>

The following example shows how to set the sales tax and shipping fees cost parameters when the values are variable. You must add a JavaScript function or script variables that provide the tax and shipping fee values for the conversion.

For the <noscript> element, the server that serves the web page will need to dynamically generate the source URL in order to include the revenue and cost values before loading the page.

<script type="text/javascript">
    // An example function that returns
    // the revenue value of the conversion.

    function getRevenue() {
        // Replace the content of this function with your own code
        // that returns the revenue value.

        return Math.ceil(Math.random() * 10);
    }

    // An example function that returns
    // the sale tax value of the conversion.

    function getSalesTax() {
        // Replace the content of this function with your own code
        // that returns the revenue value.

        return Math.ceil(Math.random() * 10);
    }

    // An example function that returns
    // the shipping fee value of the conversion.

    function getShippingFee() {
        // Replace the content of this function with your own code
        // that returns the revenue value.

        return Math.ceil(Math.random() * 10);
    }
</script>

<script type="text/javascript">
    mstag.loadTag(
        "analytics", 
        { dedup: "1", domainId: "XXXXXX", type: "1", taxcost: getSalesTax(), shippingcost: getShippingFee(), revenue: getRevenue(), actionid: "XXXX" }
        )
</script>

<noscript>
    <iframe src="//flex.msn.com/mstag/tag/<Bing Ads-defined GUID Goes Here>/analytics.html?dedup=1&domainId=XXXXXX&type=1&taxcost=&shippingcost=&revenue=&actionid=XXXX"
            frameborder="0" scrolling="no" width="1" height="1" style="visibility: hidden; display: none">
    </iframe>
</noscript>

Setting the dedup Parameter

If a user clicks an ad, goes to your website, purchases an item, returns to your website within the conversion period, and then purchases another item, the dedup parameter determines whether to count one conversion for the click or count each conversion for the click.

The following are the possible values:

  • 1 — Count only one conversion for the click regardless of the number of conversions that the user made during the conversion period.

  • 2 — Count one conversion per unique referring URL. The referring URL is the URL of the web page with your published script.

  • 3 — Count all conversions for the click made by the user during the conversion period.

If you set dedup to 2 or 3, the conversion report can show a higher number of conversions compared to the number of clicks.

<script type="text/javascript">
    mstag.loadTag(
        "analytics", 
        { dedup: "1", domainId: "XXXXXX", type: "1", revenue: "<REVENUEVALUEGOESHERE>", actionid: "XXXX" }
        )
</script>

<noscript>
    <iframe src="//flex.msn.com/mstag/tag/<Bing Ads-defined GUID Goes Here>/analytics.html?dedup=1&domainId=XXXXXX&type=1&revenue=<REVENUEVALUEGOESHERE>&actionid=XXXX"
            frameborder="0" scrolling="no" width="1" height="1" style="visibility: hidden; display: none">
    </iframe>
</noscript>

Issues to Avoid

The following should be avoided when coding your web pages that include an analytics script.

  • The use of jQuery or other such mechanisms for loading the scripts, because some implementations may execute scripts out of order or otherwise interfere with the Bing Ads campaign analytics pipeline.

  • The use of the <base> element because it may cause a message to display to the user that indicates that the page is loading an unsecure script. This can happen if the protocol for your website uses HTTPS and you use the <base> element to load a web page using the HTTP protocol. Because the analytics scripts do not use an explicit protocol for the source URI, they will attempt to load by using HTTP instead of HTTPS, which will generate the message.

Troubleshooting Deployed Scripts

The following steps may help troubleshoot campaign analytics issues, for example no conversions or revenue being tracked.

  1. Verify that campaign analytics is enabled for the account. In the Bing Ads web application, go to Tools - Campaign Analytics.

  2. Confirm that your ad is delivered by using one of your keywords as a search query.

  3. With your mouse or other pointing device, hover over the delivered ad or right-click and copy the redirect URL. The URL should be of the form http://x.r.msn.com, where x is your account identifier. If the URL is http://0.r.msn.com then campaign analytics is not enabled for the account of the ad that was delivered by your search query.

  4. Run a tool to capture network traffic, for example Fiddler.

  5. Click on the ad and navigate your web site to step through a test conversion.

  6. After your conversion page has loaded, inspect the network trace. You should observe one or more calls to host flex.msn.com, and finally a call to host x.r.msn.com where x is the value of your account identifier and corresponds to your script's domainid. The URL should also contain parameters representing the conversion, action identifier, and revenue or shipping if specified in your script. For example, /?type=1&domainId=<accountid>&dedup=1&actionid=<actionid>&revenue=<revenuefromscript>.

Community Additions

Show:
© 2014 Microsoft