Question

Is it possibile to use country attribute to assign a timezone?

  • 25 May 2024
  • 3 replies
  • 50 views

Hey! 👋🏾

I need some help: I have a city attribute representing a city my users are from f.e. Copenhagen, London. 

Is it possibile to use this data with create or update person + Liquid to assign the Europe/Copenhagen and Europe/London as my timezone attribute, so I can send comms using timezone feature?

How would it look like?

I would appreciate your help!


3 replies

Userlevel 2

Hi Johanan,

Thanks for reaching out about this.

While there isn’t a Liquid filter that specifically detects the timezone based on the city set, if you have a predictable data set, you could create a data campaign which does some of this for you. Here is how that “Create or Update person” action could look:
 

 

As I mentioned above, you can see that this would only work with a predictable set of data - this action would update the timezone attribute with European regions. Therefore, you’d need to find a way to only send the cohort of users through your campaign that would fit into European regions.

Let us know if you have other questions about this!

Userlevel 1

@Johanan if Ryan’s solution is not enough or feasible as your city attribute does not contain really clean data that you are able to compose into a Europe/{{customer.city}} string, you would have to integrate a web service that looks up a city and returns the official timezone. Such a service can be integrated via Webhook. 

 

Based on this article, I believe you have to combine 2 services that Google offers (even for free, if you stay within certain limits). 

https://stackoverflow.com/questions/55901/web-service-current-time-zone-for-a-city

  • Geocode API that returns latidude/longitude for an address (which can be a city name) → maybe it’s even a good idea to store lat/long info also in a separate attribute in c.io as it’s more exact than just the city name
  • as a 2nd step, you use Google’s Timezone API that returns the timezone for any lat/long → store this in c.io timezone attribute

You have to activate those APIs in your Google Cloud Platform account (and create one if you don’t have one yet). Then use 2 subsequent Webhook calls in a data-driven campaign that triggers if a user registers (or similar event where the city attribute is filled or changed).

 

 

As an additional idea (as going via these APIs is kind of complicated still), you could try to store the timezone attribute directly. Depending on whether you have a mobile app or a browser-based application, your frontend would directly pass along the timezone to c.io when you send an identify call. 

Modern browsers e.g. support this in javascript:

Intl.DateTimeFormat().resolvedOptions().timeZone

So if you would modify your tracking script a bit to get this timeZone, and then assign the value to a timezone variable that you include in your c.io identify call, you would store the timezone based on the settings of the browser (or the mobile phone in mobile app case). 

Thank you both! It’s very helpful!

Reply