Tracking scripts (Google Analytics)

Modified on: Thu, 16 Nov, 2023 at 10:48 AM

Print

Tracking scripts

Aiming for high conversion on your website, it is imperative that you track the activity on your website. More and more tracking/analytics solutions such as Google Analytics come to your aid so you can properly analyze the behaviour of your website visitors. 

The BookDirect is built with that in mind and allows the usage of tracking scripts.

Important: Tracking scripts work only with Inline Integration.

In order for the BookDirect to be PCI DSS compliant, the tracking script is not added to it directly, instead, you must add it to the page of your website where the BookDirect is integrated.  

We have conveniently prepared basic scripts for the 3 Google Analytics versions.

Note: Universal Analytics will soon be deprecated (1 June 2023). Google suggests migrating to Google Analytics 4 as soon as possible. 

To locate them, simply click on the 'Tracking scripts for page views' button in the BookDirect settings.

There you will see the 3 scripts and you simply need to enter your Google Analytics ID in the respective field - Measurement ID for the Analytics version you are going to use. Once entered, the script is complete. 

From there, simply copy the scripts and paste them in your website code:

- script 1 should be added in the <head> tag of your website.

- script 2 should be added in the <body> tag of your website.

Important: The above scripts track page views/traffic only.

Conversion tracking

Conversion tracking heavily depends on the configurations of your Google Analytics account and what 'events' you use. However, we generally recommend that you use the built-in 'events' as they are fully configured with their 'parameters'. This way, you can easily track the Clock PMS+ parameters (seen below) of a completed booking in Google Analytics. Below you can see an example conversion tracking script.

Important: You still need to apply the regular 'page_view' script in your <head> tag, while adding the conversion script in the <body> tag.

Example:

<script>
   window.clockPmsWbePageViewCallback = function (params) {
     gtag('event', 'page_view', {
             page_title: ['BookDirect', params.hotelName,
params.pageName].join(' / ')
     });

     // Start of Custom Tracking Script
     if (params.pageName === 'completed') {
       gtag('event', 'purchase', {
         page_title: ['BookDirect', params.hotelName,
params.pageName].join(' / '),
         currency: params.totalPriceCurrency,
         transaction_id: params.bookingNumbers.join('-'),
         value: (params.totalPriceCents / 100).toString(),
         items: [
           {
             item_name: 'Accommodation',
             item_category: params.stay,
             item_category2: params.arrival,
             item_category3: params.departure,
           },
         ],
       });
     }
     // End of Custom Tracking Script
   }
</script>

What we have done with the above:

  • We are using the built-in 'purchase' Google Analytics event.
  • The script will work on the 'completed' page of the BookDirect - the page once a booking is created.
  • The script will transfer the following information:
    • Currency
    • Booking number - we use the 'transaction_id' parameter of the 'purchase' event. We also use the .join('') function to have the booking number as one whole number.
    • Price - we use the 'value' parameter of the 'purchase' event. Since the value is in 'cents', we also adjust it to be divided by 100 and converted to 'string', to receive the price normally.
    • Since 'items' is a required parameter for the 'purchase' event, we also hardcoded 'item_name'.
    • We use the 'item_category' parameters of the Google Analytics 'purchase' event to transfer arrival, departure and stay.

You can find all Clock PMS+ parameters which you can transfer to Google Analytics (and on which pages of the BookDirect they are available) in the 'Custom Tracking script' section (image below). You can use any of them for your tracking as long as you match them to a corresponding parameter in your Google Analytics 'event'. Furthermore, you can also track similar information not only on the 'completed' page but also on previous pages (as long as that parameter is available for the page).

Note: Check out how to link your Google Ads account with GA4 to get full-cycle data in Analytics.

Custom tracking scripts

Of course, you can use other means and systems for tracking. In that case, you can use the Custom tracking script. The way that the tracking works is that you do not add the script within the engine, instead, it is added somewhere on the same page where you have integrated the engine. Then, using a callback script you can take data from the booking creation session:

You simply need to add your tracking script within the callback script. You also have a list with the currently available parameters for tracking.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.

On this page