Add weather information to your Google Analytics with Tealium | Articles

In this article I’ll explain how to add weather information to your Google Analytics data using Tealium. This article is rather technical, so if words like JavaScript, JSON, PHP and server scare you, this article might not be the right article for you.

Collecting the weather data

First we need to collect the weather data for the current location of the visitor. We can do this with a simple PHP script on our server that gets the current location of the visitor based on the visitor’s IP address and then looks up the weather information for that location. We’ll upload this script to our server and name it weather_script.php.

tealium weather data 1

Here are the steps in the script explained:

  1. Our script will be outputting JavaScript, so we send the correct header info to the browser.
  2. We don’t want to output script errors when something goes wrong, so we disable them here.
  3. Here we get the IP address of our visitor.
  4. With the Geoplugin service, we can get the corresponding geolocation info for our visitor’s IP address.
  5. When we have the geolocation data, we can get the actual weather info for that location. Note that you need to register for a free API key in order to use the Open Weather Map service.
  6. Here we output the weather data to the browser in a JavaScript call to so it’ll end up in our Data Layer.

This PHP script, when called from a browser, will output a JavaScript function call similar to the following:

Tealium weather data 2

Data Layer

When our script is working, we need to set up our Data Layer. Log in to Tealium IQ and go to Data Layer. Add the following variables:

Tealium weather data 3

Load Rules

After we’ve set up the Data Layer, it’s time to set up the Load Rules. To do this, click the Load Rules  tab.

The first Load Rule we need, will fire whenever the weather script has not yet loaded in the current session. We can check this by checking if our weather_done cookie does not equal weather_done.

Tealium weather data 4


We also need to configure two tags. We can do this in the Tags tab.
The first Tag will load the weather script if weather has not loaded before in this session. Click the Add Tag button and add a new Tealium Generic Tag.

Tag Configuration

Tealium weather data 5Load Rules

Select Weather has not loaded this session 

Tealium weather data 6

The second tag will send the weather data as custom dimensions to Google Analytics. Click the Add Tag button and add a new Google Universal Analytics tag.

Tag Configuration
Tealium weather data 7

Load Rules

Select Weather has loaded

Data Mappings

Tealium weather data 8


The last thing we need to do (before we publish) is to persist the fact that the weather has run in this session in a cookie. To do this, go to the Extensions tab.

Click the Add Extension button to add a Persist Data Value extension.

Tealium weather data 9

Save and Publish

Click the Save/Publish button to save the configuration and publish it.


Although some technical knowledge is required, you can see in the steps above that it’s not that difficult to add this invaluable data to your Google Analytics data with Tealium. Depending on your needs, or the needs of your client, other information can be added in a very similar way. The possibilities are endless: public transportation attendance, public holidays, stock prices…

publication author david peeters
David Peeters

| LinkedinThis email address is being protected from spambots. You need JavaScript enabled to view it.


Get in touch

Semetis | Boulevard Saint-Lazare 4, 1210 Brussels - Belgium

Connect with us

Cookie Policy

This website uses cookies that are necessary to its functioning and required to achieve the purposes illustrated in the privacy policy. By accepting this OR scrolling this page OR continuing to browse, you agree to our privacy policy.