NAV Navbar
  • Introduction
  • Simple Installation
  • Advanced
  • Introduction

    mhct.js is the call tracking javascript that enables Mediahawk to work on your website. For more information on what Mediahawk is please visit https://www.mediahawk.co.uk

    MHCT works by parsing your HTML document and then communicating with the Mediahawk server as described below:

    How MHCT works

    Simple Installation

    Javascript

    <script>
    var _mhct = _mhct || [];
    _mhct.push(['mhCampaignID','VA-00001']);
    !function(){var c=document.createElement("script");c.type="text/javascript",c.async=!0,c.src="//www.dynamicnumbers.mediahawk.co.uk/mhct.min.js";var i=document.getElementsByTagName("script")[0];i.parentNode.insertBefore(c,i)}();
    </script>
    

    To install the Mediahawk Call Tracking (mhct) code, you need to insert the javascript provided to you when setting up your dynamic URL, making sure your mhCampaignID is set correctly. This can be included anywhere within your page, ideally between the <head></head> tags.

    HTML

    <span class="mediahawkNumber1 mhMobile">01234567890</span>
    

    Once the javascript file has been included, you then need to add the appropriate mediahawkNumberX class to any phone number you wish to replace with your Mediahawk telephone number, making sure you replace X with the appropriate pool ID. You can also add the mhMobile class if you want to turn the number into a clickable link.

    Advanced

    Options

    The only option required for MHCT to run is the mhCampaignID - there is no need to define any other options or call any methods unless you are trying to use the advanced options and methods.

    _mhct

    var _mhct = _mhct || [];
    

    Before calling our javascript, you must define a array variable called _mhct that contains any setup options.

    mhCampaignID

    _mhct.push(['mhCampaignID','VA-00001']);
    

    Before including our javascript file, you must push mhCampaignID to the _mhct array with the value of your dynamic URL ID.

    enabled

    _mhct.push(['enabled',false]);
    

    If you wish to disable MHCT to not track your users, push a key of enabled with a value of false to _mhct before including our javascript.

    mhAutoChange

    _mhct.push(['mhAutoChange',false]);
    

    If you want MHCT to track the user and collect the telphone numbers from our server but not change the numbers in the UI, push a key of mhAutoChange with a value of false to _mhct before including our javascript.

    Methods

    Once our javascript has loaded, you will have an mhct object of the name mhct available for use. It will contain the following methods:

    enabled(value)

    mhct.enabled(true); // true or false
    

    You must pass a boolean variable to this method, failure to do this will cause a console error.

    If you want to enable or disable MHCT, this can be done using this method. Once disabled, MHCT will no longer track the user or change any numbers on the current page. The state of this does not persist across pages and persistence must be handled outside MHCT.

    When MHCT is first enabled, it will begin to track the user and will change any phone numbers found on the website.

    This method returns the value of the enabled() method after performing any update.

    enabled()

    mhct.enabled(); // true or false
    

    Use this method to check whether MHCT is enabled. This method returns true if it is enabled, or false if not.

    changeMHNumbers()

    mhct.changeMHNumbers();
    

    Call this method if you want MHCT to change the numbers in the UI. It does not make any calls to our servers and just changes the UI.

    Use this in conjunction with the mhAutoChange option

    reload()

    mhct.reload();
    

    If you wish MHCT to parse the page and re-generate any numbers that are found, call this method.

    This can be useful if the page contents are loaded via AJAX and you want to trigger a new page load within Mediahawk without actually reloading the page.

    getVisitorMHRI()

    mhct.getVisitorMHRI(); //a4WIy4NJnY
    

    If you wish to retrieve the Visitor MHID to store or track for future use, this can be collected using this method. It returns a string.

    getVisitMHRI()

    mhct.getVisitMHRI(); //Bd7cPPWn49
    

    If you wish to retrieve the Visit MHID to store or track for future use, this can be collected using this method. It returns a string.

    trigger(dimensionIndex [, data])

    mhct.trigger('dm1', {'value' => 1.234, 'text' => 'Additional info'});
    

    If the dimension index specified is invalid or invalid data is provided, a console error will be caused.

    If you wish to send data associated with Call-to-Action tracking, this can be done using this method.

    Call-to-Action tracking can be of type sum or count.

    dimensionIndex is the identifier associated with the dimension where data will be pushed. Possible values: dm1 to dm10.

    data is a JavaScript object that holds additional information to be pushed, and has parameters value and text.

    FAQs

    Disable/Enable Tracking

    <script>
    var _mhct = _mhct || [];
    _mhct.push(['mhCampaignID','VA-00001']);
    _mhct.push(['enabled',false]); //Disable Mediahawk
    !function(){var c=document.createElement("script");c.type="text/javascript",c.async=!0,c.src="//www.dynamicnumbers.mediahawk.co.uk/mhct.min.js";var i=document.getElementsByTagName("script")[0];i.parentNode.insertBefore(c,i)}();
    </script>
    
    <!-- Check whether a user is happy to be tracked by Mediahawk -->
    
    <script>
    //If the user is happy, load MHCT
    mhct.enable(true);
    </script>
    

    Sometimes there are situations where you don't want to track a user until they have agreed to be tracked.

    In order to do this, you will need to first disable MHCT using the enabled option, then once you are happy to track the customer, you can enable MHCT using the enabled(true) method which will begin tracking the user and change any telephone numbers.

    Triggering Call-to-Action tracking

    // Triggering a count
    mhct.trigger('dm1');
    
    // Triggering a sum with a variable
    var price = document.getElementById('item_price');
    mhct.trigger('dm2', {'value' => price, 'text' => 'Purchase value.'});
    
    // Triggering a count on form submit
    $("#productForm").submit(function(){
      mhct.trigger('dm3', {'text' => 'Form submitted by user.'});
    });
    

    To be able to use the trigger() method, you must first set up a Call-to-Action tracking in Mediahawk. Once set up, it can then be triggerered with the desired data.

    Triggering a count only requires the dimensionIndex to be passed with the call.

    Triggering a sum requires both the dimensionIndex, as well as the JavaScript object holding the value property.

    Glossary

    Visitor

    A Visitor is an individual machine that may have multiple visits assigned to them. A visitor is tracked across multiple visits using a local cookie.

    Visit

    A visit is a collection of pages that are grouped together. A visit belongs to a Visitor.

    MHID

    An MHID is a uniquely identifiable ID that can be used within the Mediahawk Reporting platform to retrieve details about an item.

    Call-to-Action tracking

    A Call-to-Action tracking is a way of sending additional information into the Mediahawk platform. Before it can be used, it must be set up within the Mediahawk reporting platform.

    A Call-to-Action tracking can be of type count or sum. This affects the way associated data is displayed within reports.