Tracking Semantic SEO with Google Analytics and Tealium

Subscribe to our monthly newsletter to get the latest updates in your inbox

With the relevance of Semantic Search Engine Optimization—and more in particular the role JSON-LD plays in that scenario—if your SEO consultant or agency is not talking "semantics" it's likely you are getting what I call "2009 SEO" (and that is to put it mildly). Here is a short description of JSON-LD from from Aaron Bradley:

JSON-LD is JSON-based serialization for linked data – literally JavaScript Object Notation (JSON) for Linked Data (-LD). That is, a standards-based method of creating machine-readable data across websites.

Content Analysis is hard

Which content performs better on your site? It's hard to measure and very few times we go further than typical metrics like Pageviews, Avg. Time on Page, Bounce Rate, and such. If your site is transactional and Google Analytics is setup correctly you also have Page Value as metric—a weird one but it helps. (Google actually removed it from GA a few years ago and had to bring it back by popular demand.) Part of the reason why content analysis is hard is because we don't have much information about what type of text the page offers and its topic. Often times we have to guess by the URL structure:
  • mysite.com/blog/10-things-to-do-in-seattle.html
  • mysite.com/news/elections-2015-results.html
  • mysite.com/recipes/paella-valenciana.html
URL structure is not something you can rely on, and the information they offer is poor—as mono-dimensional data points usually are. Here's a hypothetical scenario: You have a car parts ecommerce site. After some SEO optimization, you want to analyze the performance of any type of content—be it news, a review, or blog post—related to a particular make (Jeep) and part type (Climate Control). Sorry! No information included in URLs is enough to provide that desired analytical flexibility.

From JSON-LD to Google Analytics

JSON-LD, as a handler for structured data, helps establish multi-dimensional data points. Imagine the JSON-LD object in every page of your car parts site is populated correctly with information coming from your CMS and offers elements like:
  • content type
  • car year
  • car make
  • car model
  • part type category
  • part type subcategory
The many combinations of those in terms of content analysis should make the analyst in you salivate right now! But how do we materialize that potential in our Google Analytics implementation? Simple. Set the content elements as Custom Dimensions so you later can segment using as many combinations as you want. Okay. But not everything is Google, and many medium to large companies like to use Tealium iQ Tag Manager. No problem! We have you covered, just keep on reading.

Reading JSON-LD objects with Tealium

Obviously we need a JSON-LD object in page and here is an example. Notice that I added id="JSON-LD" to the script tag for faster identification. We'll talk about that in a minute.

Tealium Setup

Now log into your Tealium account to start the implementation.

Data Sources

Create a JavaScript Data Source per Custom Dimension (or custom Metric) you want to send to Google Analytics. No need to have them as UDO variables, so you don't even need to bother your IT team with updates in the data layer. Tip: Use neutral names like ‘custDim10,' not referencing in any manner what kind of content they serve (as it could be ‘name') but a more functional names that can be reused later seamlessly if required.

Mapping data sources to UA tag

I assume you have your Universal Analytics tag right there, so this shouldn't be too complicated or anything you're unfamiliar with. We just have to map the JavaScript Data Sources with the UA corresponding Custom Dimensions.
This is how it would look:

Extension

Now the JavsScript does a bit of magic. We need to add an Extension. Navigate to the "Advanced" tab and select "Javascript Code."
Once there, write a descriptive name such as, "JSON-LD Parser." Make sure the scope is "Pre Loader." This is important. We need all that data ready and available when Google Analytics comes to play.
Add this code, ensuring you reference correctly in getElementById() the name of the id (id="JSON-LD"). It will need some tweaking to match your needs, but it's pretty simple.
// 01. Grabs JSON-LD as text 
var jsonstring = document.getElementById('JSON-LD').textContent;

// 02. Parses string as JSON object
window.myJSONobj = JSON.parse(jsonstring);

// 03. Populates JS Custom Dimensions variables with values from JSON object
window.custDim10 = myJSONobj.name;
window.custDim11 = myJSONobj.ingredient[1];
...
What does the code do? The first line grabs all the text included in <script id="JSON-LD" type="application/ld+json"> HTML tag. The second, using browser's native JSON functions (no worries - all modern browsers support JSON encoding/decoding natively), converts flat text into an object named myJSONobj, or any other name you'd like to use. If you open browser's console and type that object name, after hitting enter you will see the object right there:
The third and last point takes properties from the object, like myJSONobj.name, and passes them to the JavaScript Data Sources created at the beginning (scoped to window: window.custDim10) this way: window.custDim10 = myJSONobj.name; Add as many of those as Custom Dimensions you want to pass to Google Analytics. If for some reason the object properties don't return any value, the Custom Dimension is not sent to Google Analytics, so you don't have to worry much about void Dimensions being sent. Lastly, you'll want to QA your implementation properly and then publish to the Production environment. We could have more than one JSON-LD object in the same page. There are two approaches to gather them all:
  • Use IDs as we described here and call them by name to convert them into regular JS objects. One per JSON-LD or al into one JS object
  • Create a JS function to parse all possible JSON-LD objects into a single JS object
This does not make a big difference, and at the end of the day you have to know what you are dealing with.

Verify Data Sent to Universal Analytics

If everything is working as expected, this is what you will see being sent to GA - using Google Analytics Debugger Chrome extension in this case. After QA in your browser, do some testing and double check that the Custom Dimensions are populated with the right values.

Conclusion

By adding semantic markup to your pages your site not only gets the benefits granted by major Search Engines, but with some few extra work in Tealium you can bring your text analysis to a whole new level. I'll end on this: Do yourself a favor and follow Aaron Bradley's blog and/or his other social channels ( Twitter or G+) for the latest in semantic SEO topic!