Tuesday’s Tip: Automatically get your visitor’s time zone

Everyone knows that calling a lead too early in the morning or too late in the evening is a sure way to start off on the wrong foot. But how do you deal with the myriad of time zones? You could try relying on the visitor’s state, but there are 15 states that span more than one time zone. You also have oddities like Arizona, where daylight saving time isn’t observed.

An easy solution is to gather the visitor’s time zone when they fill out a web form. This takes a few steps, including adding a custom field to store the time zone, and modifying a web form to automatically fill a hidden field with the visitor’s time zone. To see this tip in action, check out our demo web form.

If you aren’t familiar with creating custom fields, please review the documentation at the Infusionsoft website. You’ll need to create a custom Text field for the Contact Record. We called ours Timezone.

Next, you need to find the field’s database name. On the custom fields page, click the View the field database names (for the API) link. This will open a new window that lists your custom fields and their database names. As you can see in the screenshot, our field’s database name is Timezone0. Write this down, you’ll need it later.

Our field's database name is Timezone0

Our field’s database name is Timezone0

Add your time zone field to your web form as a Hidden field. This will make the field invisible to the visitor, but will still allow the time zone to be saved to Infusionsoft.

Next we need to add some JavaScript that will automatically determine the visitor’s time zone, and save it to your time zone field. Edit your web form and add an HTML Snippet with this code:

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jstimezonedetect/1.0.4/jstz.min.js"></script>
<script type="text/javascript">
// <![CDATA[
jQuery(document).ready(function(){
    var timezone = jstz.determine();
    jQuery('#inf_custom_FIELDNAME').val(timezone.name());
});
// ]]>
</script>

You’ll need to make one change to the code. Replace FIELDNAME with the field’s database name you retrieved earlier. For our example, we would replace it with Timezone0.

Here is a screenshot of the code in action on a simple web form with a visible time zone field:

Time zone automatically filled in by our HTML Snippet

Time zone automatically filled in by our HTML Snippet

You can see that America/Chicago was automatically selected. I live in San Antonio, which is in the Central time zone, so America/Chicago (also the Central time zone) is the correct choice.

Future tips will help you turn the IANA time zone location into something a little more useful, but I highly recommend starting to collect time zones now even if you don’t plan on using them yet. It takes just a few minutes to set up and gives you a lot of flexibility in the future, such as sending emails at a precise time regardless of where your lead lives.

3 Comments

  1. Thanks for this Jacob, As someone who has clients all over the world I would like to see a numerical number that shows + or – the timezone is away from EST (as that is the time that IS uses). That way you could sort everyone by world time zones rather than country timezones and make sure they get sent at the right time.

    Reply
    • Saving the offset from US Eastern time would introduce a different set of challenges. For example, US Eastern observes daylight saving time, but much of the world doesn’t or starts/stops on different dates. In addition to that, it isn’t uncommon for localities to change their time zone so it has a different offset from UTC or observes daylight saving time in a different way (for example, Utah is looking at dropping DST). This means your offset could be off by one more hours several times a year. The only way to somewhat reliably know what time it is for a contact is to have the name of their time zone, and then use a current version of the IANA time zone database and the date to determine what time it would be there.

      Unless you are marketing exclusively to a specific country with a limited number of time zones, you’ll likely need to use the API. I plan on releasing some code in the next couple weeks that will give a good example of what you can do with having your contact’s time zone.

      Reply
  2. Hey Jacob,
    Great article, thanks. I just implemented this to check if the new Timezone automatic thing is going to work. I don’t think it is working yet, and there is no way to know, so this is a great way.
    Aug 2016 update included Language and Timezone of person submitting forms, but doesn’t work on my forms… so Thanks 🙂

    Reply

Leave a Reply