Importing content metadata, such as author, date published, or article category, enables you to group content according to these dimensions.
In this article:Scenario
You are a publisher and you want to see which authors on your site are most popular. To measure popularity, you'd like a report that sums the pageviews of each author's articles.
Step One: Decide what data to import
You maintain a data file outside of Analytics that associates each article with an author and you plan to upload this information into Analytics.
Step Two: Create the custom dimension
Since "author" doesn't exist as a dimension in Analytics, you'll need to create it as a custom dimension.
custom dimension Name | Index | Scope |
---|---|---|
Author | 1 | Hit |
Step Three: Create the Data Set
- In Admin, navigate to the account and web property to which you want to upload data.
- Click Data Import under PROPERTY.
- Click New Data Set.
- Select Content Data as the Type.
- Name the Data Set Authors and Articles.
- Select one or more views in which you want to see this data.
- Define the Schema using the example below as a model.
Schema example
While you don't explicitly send article ID in your hit data, you do include an article ID in your page URLs. Assuming that the URLs of article pages are consistently formatted, you can use regex to match on the article_id portion of the URL. Let's say the URLs of article pages are consistently of the format http://example.com/articles/abc123.html
, where abc123
is the article_id. To join on the article_id from the URL, you would select Page as your Key, select regex refinement, and enter into the text field regex as follows: /articles/([^/]+).html$
.
Schema Settings:
Key: PageRefine with regular expression: /articles/([^/]+).html$
Imported Data: Author
Overwrite hit data: Yes
Extracting URL parameters
Special handling is provided for extracting URL query parameters such as ?param=value
in the URL http://example.com/articles/abc123.php?param=value
.
param
, select Page as your Key, then choose the refine with query parameter option, and finally type "param" into the text box. For example, if you wanted to extract a UTM ID included in the Page URL as ?utm_id=abc123, you would select refine with query parameter option and enter "utm_id" in the text box.
Step Four: Create the CSV
Generating your upload CSV file is a 2-step process:
1. Get the header for the CSV
In the Data Set table, click Manage Uploads for Authors and Articles. In the Manage Uploads table, select Choose Action > Display CSV Header. You'll see something similar to the following:
CSV header ga:pagePath,ga:dimension1
This is the header you should use as the first line of your uploaded CSV files. The table below identifies the columns:
Page | Author |
---|---|
ga:pagePath | ga:dimension1 |
2. Create a spreadsheet and export it as a CSV
Create a Google spreadsheet that follows the format above. The first (header) row of your spreadsheet should use the internal names (e.g. ga:pagePath
instead of Page) provided in the Display CSV Header dialog box shown above. The columns beneath each header cell should include the corresponding data for each header.
ga:pagePath | ga:dimension1 |
---|---|
how_to_make_pizza | John Dough |
how_to_make_doughnuts | Benny Cruller |
how_to_build_a_treehouse | Oona Limb |
how_to_make_paper_airplanes | Hellen Wings |
Export the spreadsheet as a CSV. Your file will look something like this:
ga:pagePath,ga:dimension1
how_to_make_pizza,John Dough
how_to_make_doughnuts,Benny Cruller
how_to_build_a_treehouse,Oona Limb
how_to_make_paper_airplanes,Hellen Wings
Step Five: Upload the data
You can now upload the CSV file you created to Analytics. You have two choices for uploading your data: manually, using the Analytics user interface, or programmatically, using the Management API.
Upload manually-
In the Data Set table, find the row for Authors and Articles.
- Click Manage uploads for the Colors and Sizes data set.
- Click Upload file, select the file, then click Upload.
- In the Data Set table, find the row for Authors and Articles.
- Click the data-set name.
- Click Get Custom Data Source ID…
- Make a copy of the ID.
- Follow these instructions to upload via the Management API.
Step Six: See the data in reports
Since Author is a custom dimension, it does not appear in standard reports. To see the total number of pageviews per author, you would create a Custom Report with one metric (Pageviews) and one dimension (Author).
Uploaded data needs to be processed before it can show up in reports. Once processing is complete, it may take up to 24 hours before the imported data will begin to be applied to incoming hit data.