Setting up custom code analytics services
Last updated: February 7, 2023
While FareHarbor has four types of tracking services natively supported in the Dashboard, the custom code section allows an admin user to add a multitude of conversion tracking codes. These custom codes will fire on the booking confirmation page when a user completes their booking. All of the code entered into the “Custom Code” section of the Dashboard will fire within an iframe on the confirmation page.
Generally, any conversion tracking code should work with FareHarbor. It may require some tweaking in order for the data to flow properly, but the majority of conversion tracking codes implemented have worked correctly.
Try to find documentation for any new custom code added to the Dashboard. This will make troubleshooting and implementation considerably easier and will also avoid a situation where malicious code is inadvertently added.
Code added into the custom code section will fire exactly what’s been added on the confirmation page. If the code does not come from a reputable source or have any documentation do not add it to the Dashboard.
Adding a custom code service
- Go to Settings > Analytics & Tracking
Click Add analytics service
- From the Type dropdown, choose custom code as the service type
- Add a private name describing what code is added
- Add the required code in the Code field
- If needed, add in your identifier(s) to the Identifiers field.
- Click Create analytics service
Adding Custom Code Request
Custom code can be intimitdating if you’re not used to working with any code. If you don’t feel comfortable adding custom code to the dashboard yourself, you can request the integration team adjust the code and implement it for you.
If you don’t need custom variables added to the custom code, you can paste it in yourself. Follow the steps above to paste the code into the dashboard. If you need the custom variables below adding into your code, feel free to submit a request.
Please include documentation and/or implementation instructions with your code whenever possible. This greatly increases the odds of the code working correctly.
Click here for the custom code request form.
Using the booking variable to customize tracking codes
The booking variable is used to pass booking specific information from FareHarbor to the tracking code. For example, if a tracking code contains a section for a unique purchase identifier, you can use the booking.pk variable within the tracking code to pass the FareHarbor booking number. The purchase total is another common variable tracking scripts accept within their code. Use either booking.total_in_cents or booking.total_in_dollars to pass the booking total through to the tracking code.
In order to determine which variable to use, reference the tracking code documentation. They should indicate what format the tracking code is expecting to see for the variable value. If the tracking code asks for the booking total as an integer you would need to use the booking.total_in_cents variable since that’s shown to be an integer in the value column.
The booking variable has the following properties:
| Property | Use | Value |
|---|---|---|
booking.pk |
Booking number: unique identifier of booking | integer |
booking.priceInCents |
Subtotal without tax, in cents, like 1390 | integer |
booking.priceInDollars |
Subtotal without tax, in dollars, like ‘13.90’ | string |
booking.taxInCents |
Just tax, in cents, like 120 | integer |
booking.taxInDollars |
Just tax, in dollars, like ‘1.20’ | string |
booking.totalInCents |
Price + tax, in cents, like 1510 | integer |
booking.totalInDollars |
Price + tax, in dollars, like ‘15.10’ | string |
booking.total_in_dollars |
Price + tax, in dollars, like 15.10 | integer |
booking.currency |
Currency transacted, like ‘USD’ | string |
booking.currencyLowercase |
Currency transacted, like ‘usd’ | string |
booking.customerCount |
Total number of customers on this booking | integer |
booking.onlineRef |
The booking ‘ref’, if any | string |
booking.item.pk |
Unique identifier of item | integer |
booking.item.name |
Name of the item | string |
booking.item.sku |
Short/private name of the item | string |
booking.order.uuid |
Unique identifier for the order | string |
booking.order.identifier |
Alternative identifier for the order | string |
booking.order.bookingCount |
Total number of bookings in the order | integer |
booking.company.shortname |
Company’s shortname | string |
booking.company.name |
Company’s name | string |
booking.affiliate.shortname |
Affiliate company’s shortname | string |
booking.affiliate.name |
Affiliate company’s name | string |
Implementing the booking variable
The booking variable is used to send dynamic information from FareHarbor to the tracking code. You will replace text in the tracking code with the value from the property column. Consider this example script from Google Ads.
<script>
gtag('event', 'conversion', {'send_to': 'AW-123456789/AbC-D_efG-h12_34-567',
'value': 123.05,
'currency': 'USD'
});
</script>
In order to have the conversion data send the value of each individual booking, replace the “123.05” with the booking.total_in_dollars. In order to have this code work across multiple countries, we can also change the “USD” value for currency to the booking.currency variable. The updated script will look as such:
<script>
gtag('event', 'conversion', {'send_to': 'AW-123456789/AbC-D_efG-h12_34-567',
'value': booking.totalInDollars,
'currency': 'booking.currency'
});
</script>
This will send the appropriate revenue data to Google Ads so the campaign can be properly attributed with the correct purchase total.
Note: The ‘affiliate’ variables will be null if the booking was made without an ‘asn’ tag and the ‘order’ variables will be null if the company does not have cart enabled.
In links
Note: to use a variable in links, it must be wrapped in double braces, like {{ booking.pk }}.
<img src="http://example.com/?sale-id={{ booking.pk }}&value={{ booking.total_in_dollars }} />
In JavaScript
Note: when using the booking variable in JavaScript, properties must be accessed using “camel case”. For example booking.total_in_dollars must be accessed as booking.totalInDollars.
<script>
track({
'sale-id': booking.pk,
'value': booking.totalInDollars,
'company': booking.company.name
})
</script>
Using the identifier or identifiers variables to customize tracking codes
When implementing custom tracking code in the FareHarbor Dashboard, there are two fields. One for the custom code to add to the booking confirmation page and another for custom identifiers for the code. Unlike the booking variable discussed later, the custom identifiers can be anything. Usually the identifier(s) variable is a unique account ID or something similar generated by the original code. Typically the identifier is used to recycle custom tracking codes across multiple Dashboards while allowing easy injection for account specific identifiers.
In this example Bing Conversion Tag, the code section can be used across any Dashboard for tracking Bing Conversions. The only change made from Dashboard to Dashboard is the identifier variable. “27000002” has been added for this implementation replacing the client’s specific Bing account ID which would normally be included within the code.
While this example shows a single value with the Identifiers field, the value of the Identifiers field is made available as one of two variables.
If Identifiers is a single value, like "some-id" or 12345, then it’s made available directly as the singular identifier. For example:
identifier = "some-id"
If Identifiers is a dictionary/object instead, it’s made available as the plural identifiers. For example:
identifiers = {
"first_identifier": "first value"
"secondIdentifier": "second value"
}
In this case, values can be accessed like identifiers.first_identifier
Implementing the identifier or identifiers variables
Note that unlike the booking variable, the casing of properties of the identifiers dictionary wil always match exactly what you type in.
In links
Note: to use a variable in links, it must be wrapped in double braces, like {{ identifier }}.
<!-- Using identifier (singular) -->
<script src="http://example.com/?identifier={{ identifier }}>
<!-- Using identifiers (plural) -->
<script src="http://example.com/?first-id={{ identifiers.first_identifier }}&second-id={{ identifiers.secondIdentifier }}>
In JavaScript
<script>
// Using identifier (singular)
track(identifier)
// Using identifiers (plural)
track(identifiers.first_identifier, identifiers.secondIdentifier)
</script>
FAQ
My client uses a CRM that tracks customer movements through their website, can they track the customer through the booking process using custom code?
Custom code only fires on the booking confirmation page when a customer completes a booking. The only analytics service which can track customer actions within the lightframe is Google Analytics.
My client is trying to set up a conversion event to track purchases and wants to know if the event should fire on page view or click.
All conversion events to track with custom code should fire on page view and not on click.
Should I always move specific identifiers to the identifiers section or can I just paste in the code they gave me?
You can just paste in the code they gave you.
Will _____ type of tracking code work?
Probably, as long as its for tracking conversions. Try and find the documentation for it.