Home Technology How to import weather data into Google Analytics?

How to import weather data into Google Analytics?

by Yasir Aslam
0 comment

The number of people using custom dimensions, which is one of the new features of Universal Analytics, has gradually increased. I think that the number of sites that set internal data such as client IDs and attributes of member information held by web services as custom dimensions has increased recently.

thumbnail 1 1

However, there are still sites that set external data such as weather information, train operation information, event data (not Google Analytics events, but seminars, concerts, match cards at the nearest stadium, etc.) as custom dimensions and use them for analysis. Isn’t there a few?

With the addition of powerful data import capabilities in Universal Analytics, you can easily ingest this data. In this article, I will show you how to import weather information into Google Analytics.


Benefits of incorporating weather data into Google Analytics

Business sales and website visits often depend on weather data. For example, if it is a delivery service, there are many cases where a lot of sales go up on rainy days. In addition, I think that many site visits occur during stormy weather such as heavy rain, snow, and typhoons for the websites of airports and airlines. It’s also possible that beer sales are tied to temperature.

Although it is not possible to analyze by linking to these weather data with the default Google Analytics function, such analysis is possible if you prepare the data yourself and put the data on Google Analytics.

What is data import?

The data import function of Google Analytics is a mechanism for linking offline data and measurement data. Offline data is registered by uploading a CSV file. In addition to manual uploads, API uploads are also possible, so regular data updates are possible.

let’s try it

Overall composition

In this article, the goal is to easily import weather data into Google Analytics and make it ready for analysis. Therefore, in order to aim for a configuration that can be started immediately for free, we assume the following contents. If necessary, you can replace it with another technique and have it executed.

  • Use APIs that are available free of charge
  • Use Google Sheets Apps Script from calling API to uploading data
  • Set weather data for each prefecture (because setting for each municipality would result in a huge amount of data, making it difficult to process with Apps Script)

Decide which weather data API to use

To get weather data, you need to use the API of the data provider. If you look up the services that provide APIs, you will find services like the one in the table below. As you can see, commercial use is prohibited, and most of them are paid APIs. When it comes to commercial use for free, it seems that Open Weather Map is the only choice. This article also assumes the Open Weather Map. Although the Open Weather Map API can be used free of charge, it is recommended that you register as a user and issue an application ID, so please register as a user and issue an application ID.

Service name personal use commercial use
weather hacks Yes Impossible
tenki RSS Yes Corporate management is not allowed
Yahoo! Weather/Disaster RSS Yes Impossible
weather API Impossible Paid
content pocket Impossible Paid
Wave Hunter Impossible Paid
Open Weather Map Yes Yes (paid plan also available)

Create a dimension to set weather data in Google Analytics

Create a custom dimension to view the weather data as a dimension. There are already many articles on how to create a custom dimension, so I will omit it, but the settings are as follows.

item set value
name weather data
range session
Active checked

Prepare dataset for data import

Regarding data import, I think there are few sources of information, so I will explain it a little carefully.

Select “Import data” from Analytics settings
From the “Import Data” menu, click “+ New Dataset”
On the Select Dataset Type screen, select “Regional Data” and go to the next step.
Specify a meaningful view (in this case, “weather data”) in the name field of the details of the dataset, and specify a valid view (basically, specify all views)

In the dataset schema settings, select the key item (dimension) and the import storage destination item (dimension). Here, specify “Area ID” as the key, and register “Weather data” (the dimension name created in the custom dimension) in the imported data.

And for “Overwrite hit data”, it doesn’t matter which one this time, but select “Yes”
Finally, click the Get Custom Data Source ID button and make a note of the ID string. We will use the ID string later

Prepare a template of data in a spreadsheet

Create a Google Spreadsheet for temporary storage of weather and regional data. This time, I prepared a template so that it can be easily created. Open the spreadsheet from the URL below, copy it to your own Google Dosc and use it.

This spreadsheet has two sheets. The “Data” sheet is a sheet for temporarily storing regional data and current weather data for each region. The “Configuration” sheet has setting items necessary for uploading weather data to Google Analytics.

After copying the spreadsheet and creating one for yourself, display the Configuration sheet and change the setting items according to your Google Analytics information. Also, enter the application ID for using the Open Weather Map API and the custom data source ID for importing Google Analytics data obtained in the previous steps in the Configuration sheet.

Check spreadsheet script activity

There should be “GA Weather Import” in the Google Sheets menu. By clicking “Manual execution” in this “GA weather import”, you can execute the import process to the end. After waiting for a while, I think that the weather data for each region will be obtained and set in the E column via the API. Also, if there are no problems with linking with Google Analytics, you can check that the data has been added to Google Analytics’ “Analytics Settings > Property > Data Import > Manage Uploads”.

If the data is not uploaded to Google Analytics, it would be a good idea to check whether the settings entered in the Configuration sheet are correct, and the permissions around the Google Analytics API (For more information on Google Analytics API permissions, see below. write another article).

If you can execute up to the upload without any problems, then all you have to do is execute this process automatically and periodically. Now, click “Register Trigger” in “GA Weather Import” in the spreadsheet menu. A trigger is set to upload weather data every 6 hours every day. Upload time is 0-1:00, 6-7:00, 12-13:00, 18-19:00. If you want to temporarily stop automatic execution, you can stop automatic execution by selecting “Delete trigger” in the same menu.

summary

Using Google Analytics’ “Import data” function, you can easily import weather data into Google Analytics! I would appreciate it if you thought. The “import data” function itself is still a function with little information, but it will be a very cooperative weapon once you know how to use it. Let’s import various data and analyze them.

You may also like

Leave a Comment