I recently looked at the CSS chapter of the Web Alamanc and had some thoughts. Here, Stefan Judis looks at the whole thing and rounds up the most interesting bits to him. Here are most of them:
20% of sites don’t compress their JavaScript.
React is on 5% of sites while jQuery is on 85% of sites. (Hence my tongue-in-cheek Tweet)
Native JavaScript imports are under 1% (we’re all still bundling, which for the time being, we’re told is the way to go).
Flexbox usage is at 50% and grid only 2%. (I previously remarked at how wild I think this is, with browser support being not terribly different and grid being, IMO, generally more useful.)
20% of sites use responsive images. (Interesting as WordPress does it out of the box, and powers some 34% of the web. Maybe a lot of really old outdated WordPress versions out there?)
font-display usage is at 26%, which blows me away as it’s fairly new and a little esoteric (as much as I love it).
HTTPS at 80%. Also surprising considering what a pain in the butt it is if your host doesn’t make it a default part of their offering.
4 of 5 sites ship with color contrast issues. Not suprising, but I wonder how many false positives are in here. I’ve seen a lot of that with automated tooling.
1 of 4 sites don’t specify a lang attribute.
4 of 5 forms don’t ship with labels for their input elements. WHATTTTTT.
0.44% sites use a service worker. I’m a fan, but they are (1) too hard and (2) feel too dangerous to dabble in.
2 of 3 pages have a huge content shift while loading. (Remember to put width and height attributes on images now, which prevents content shifting. Huge.)
We hear about WordPress powering 1/3 of the web, but another interesting related stat is that if you’re using a CMS, there is a 75% chance it’s WordPress.
Only 20% of sites use a CDN (for the HTML). I’m sure it’s higher for assets.
We’re still pushing around a 2MB average page size. Everything depends, but if we’re trying to be consious people in general, let’s say we aim for half that.
We’re all familiar with the phrase, “A picture is worth a thousand words.” And the same is true for good design.
Whether you’re viewing a print advertisement, a website page, or a blog post, the design has a major impact on your perception of the information and the brand.
Think back to the last time you read a 3,000 word blog post with absolutely no images, no thought put into the layout, and no charts or graphs. Unless the information was incredibly compelling, your experiencing reading the blog post was probably pretty unmemorable. Maybe you even stopped reading and clicked off the page half way through. Being “unmemorable” is something that brands today can’t afford if they want to be competitive and win business.
And that is exactly what is at the root of this article—why marketers need to make design a priority in their content marketing. According to the Content Marketing Institute (CMI), over 90% of B2B marketers and 86% of B2C marketers are using content marketing to engage with their audience and generate leads.
Those statistics prove that your prospective customers are facing content overload. To break through the noise, your brand’s marketing assets need to stand out. In fact, you could argue that the design of your content could be the difference between a new customer and a lost sale.
Content + Emotion = Better Sales
You might be wondering how design even fits into a content marketing strategy. After all, you don’t often use the words “writing” and “design” in the same sentence. Writing itself isn’t inherently visual, it’s about getting the facts onto paper and shaping it into a compelling and informative argument with the intent of generating intrigue.
But here’s the thing—design is linked to emotion, on both a conscious and subconscious level. When you decided to stop reading that boring 3,000 word blog post, it’s because you didn’t feel a connection to the content or the brand. The experience didn’t trigger an emotion that made you want to learn more.
We also know that emotion has a huge impact on your brand’s ability to sell to customers. And the design of your content marketing assets can change the way people feel when they’re engaging with them. For example, most people would agree that seeing data laid out in an infographic is much more powerful than reading it in paragraph form.
The design of your content also determines how accessible it is. That’s one of the reasons why videos, webinars, and even podcast hosting are effective lead generation strategies for many companies. You could publish a podcast script as a written Q&A on your blog, but it’s not as accessible as being able to listen to it passively or skip to sections you’re most interested in.
5 Tips for Using Design in Your Content Marketing
A good content marketing strategy starts with—you guessed it—good content. Part of that is using marketing analytics to track the types of content your audience is most interested in. But there’s always room to level up, and integrating good design into your content marketing is one way to do that. Here are some design tips that you can integrate into your content marketing to increase engagement.
1. Use Stock Images Sparingly
Stock photos can be both a blessing and a curse for marketers. On one hand, using stock photos will save you a lot of time and money. But they tend to lack authenticity and are often overused. That can make your content feel generic and uninspiring.
The images you use in your content as just as important as the writing. In fact, content that has images gets 94% more views than content without visuals. If you are going to use stock images, be very selective and use the ones that feel the most real. Better yet, pull out your camera and stage a mini photoshoot in your office for photos that show off your brand’s human side. Another great way to limit your use of stock photos is to use screenshots or create visuals with your data, and paste them throughout the content.
2. Invest in Infographics
Marketers and consumers alike are drawn to infographics. Using infographics can boost your site traffic by 12%, and over 40% of marketers say that infographics are the most engaging form of visual content. Infographics can feel like a daunting task, especially if you don’t have a designer on staff. But there are dozens of tools that can make infographic design a breeze.
Infographics are a great addition to your content marketing because of their versatility. You can add an infographic to a relevant blog post, cut it down into snippets with the most compelling data, and even post it on social media. Infographics are the most effective way to illustrate data, charts and graphs, and make the information memorable. They are easy to digest, highly shareable, and some even go viral.
3. Publish More Ebooks
When it comes to content marketing assets, ebooks are one of the most effective forms of content. It allows you to put a high volume of information into an easy-to-read, easy-to-digest format. Unlike traditional blog posts or white papers, ebooks don’t feel like information overload. It’s a great way to implement design into your content and drive your audience to learn more.
According to HubSpot, your brain can process visual information nearly 60,000 times faster than plain text. So in your next ebook, make sure you’re including images, screenshots, charts and graphs to help you readers remember the highlights. A combination of text and graphics can convey your information in a way that evokes emotion and creates a sense of urgency for the reader that will make them more likely to convert.
The Bottom Line
Good design is an important element of any effective content marketing strategy. Using design can amplify your content, attract more prospective customers, and entice readers to take action and learn more. There are dozens of tools, marketing courses, and resources available to help you determine which types of assets to create, and how to infuse design into your strategy. Marketers today need to be using their content to differentiate their brand from others in the industry, and using good design can help create a lasting impression and elevate your brand’s identity.
Over the past decade, there has been a seismic shift towards conversational interfaces. As people reach ‘peak screen’ and even begin to scale back their device usage with digital wellbeing features being baked into most operating systems.
To combat screen fatigue, voice assistants have entered the market to become a preferred option for quickly retrieving information. A well-repeated stat states that 50% of searches will be done by voice in year 2020. Also, as adoption rises, it’s up to developers to add “Conversational Interfaces” and “Voice Assistants” to their tool belt.
Designing The Invisible
For many, embarking on a voice UI (VUI) project can be a bit like entering the Unknown. Find out more about the lessons learned by William Merrill when designing for voice. Read article ?
What Is A Conversational Interface?
A Conversational Interface (sometimes shortened to CUI, is any interface in a human language. It is tipped to be a more natural interface for the general public than the Graphic User Interface GUI, which front end developers are accustomed to building. A GUI requires humans to learn its specific syntaxes of the interface (think buttons, sliders, and drop-downs).
This key difference in using human language makes CUI more natural for people; it requires little knowledge and puts the burden of understanding on the device.
Commonly CUIs comes in two guises: Chatbots and Voice Assistants. Both have seen a massive rise in uptake over the last decade thanks to advances in Natural Language Processing (NLP).
Understanding Voice Jargon
Keyword
Meaning
Skill/Action
A voice application, which can fulfill a series of intents
Intent
Intended action for the skill to fulfill, what the user wants the skill to do in response to what they say.
Utterance
The sentence a user says, or utters.
Wake Word
The word or phrase used to start a voice assistant listening, e.g. ‘Hey google’, ‘Alexa’ or ‘Hey Siri’
Context
The pieces of contextual information within an utterance, that helps the skill fulfill an intent, e.g. ‘today’, ‘now’, ‘when I get home’.
What Is A Voice Assistant?
A voice assistant is a piece of software capable of NLP (Natural Language Processing). It receives a voice command and returns an answer in audio format. In recent years the scope of how you can engage with an assistant is expanding and evolving, but the crux of the technology is natural language in, lots of computation, natural language out.
For those looking for a bit more detail:
The software receives an audio request from a user, processes the sound into phonemes, the building blocks of language.
By the magic of AI (Specifically Speech-To-Text), these phonemes are converted into a string of the approximated request, this is kept within a JSON file which also contains extra information about the user, the request and the session.
The JSON is then processed (usually in the cloud) to work out the context and intent of the request.
Based on the intent, a response is returned, again within a larger JSON response, either as a string or as SSML (more on that later)
The response is processed back using AI (naturally the reverse – Text-To-Speech) which is then returned to the user.
There’s a lot going on there, most of which don’t require a second thought. But each platform does this differently, and it’s the nuances of the platform that require a bit more understanding.
Voice-Enabled Devices
The requirements for a device to be able to have a voice assistant baked in are pretty low. They require a Microphone, an internet connection, and a Speaker. Smart Speakers like the Nest Mini & Echo Dot provide this kind of low-fi voice control.
Next up in the ranks is voice + screen, this is known as a ‘Multimodal’ device (more on these later), and are devices like the Nest Hub and the Echo Show. As smartphones have this functionality, they can also be considered a type of Multimodal voice-enabled device.
Voice Skills
First off, every platform has a different name for their ‘Voice Skills’, Amazon goes with skills, which I will be sticking with as a universally understood term. Google opts for ‘Actions’, and Samsung goes for ‘capsules’.
Each platform has its own baked-in skills, like asking the time, weather and sports games. Developer-made (third-party) skills can be invoked with a specific phrase, or, if the platform likes it, can be implicitly invoked, without a key phrase.
Explicit Invocation: ”Hey Google, Talk to .”
It is explicitly stated which skill is being asked for:
Implicit Invocation: ”Hey Google, what is the weather like today?”
It is implied by the context of the request what service the user wants.
What Voice Assistants Are There?
In the western market, voice assistants are very much a three-horse race. Apple, Google and Amazon have very different approaches to their assistants, and as such, appeal to different types of developers and customers.
Apple’s Siri
Device Names: ”Google Home, Nest”
Wake Phrase: ”Hey Siri”
Siri has over 375 million active users, but for the sake of brevity, I am not going into too much detail for Siri. While it may be globally well adopted, and baked into most Apple devices, it requires developers to already have an app on one of Apple’s platforms and is written in swift (whereas the others can be written in everyone’s favorite: Javascript). Unless you are an app developer who wants to expand their app’s offering, you can currently skip past apple until they open up their platform.
Google Assistant
Device Names: ”Google Home, Nest”
Wake Phrase: ”Hey Google”
Google has the most devices of the big three, with over 1 Billion worldwide, this is mostly due to the mass of Android devices that have Google Assistant baked in, with regards to their dedicated smart speakers, the numbers are a little smaller. Google’s overall mission with its assistant is to delight users, and they have always been very good at providing light and intuitive interfaces.
Their primary aim on the platform is to use time — with the idea of becoming a regular part of customers’ daily routine. As such, they primarily focus on utility, family fun, and delightful experiences.
Skills built for Google are best when they are engagement pieces and games, focusing primarily on family-friendly fun. Their recent addition of canvas for games is a testament to this approach. The Google platform is much stricter for submissions of skills, and as such, their directory is a lot smaller.
Amazon Alexa
Device Names: “Amazon Fire, Amazon Echo”
Wake Phrase: “Alexa”
Amazon has surpassed 100 million devices in 2019, this predominantly comes from sales of their smart speakers and smart displays, as well as their ‘fire’ range or tablets and streaming devices.
Skills built for Amazon tend to be aimed at in skill purchasing. If you are looking for a platform to expand your e-commerce/service, or offer a subscription then Amazon is for you. That being said, ISP isn’t a requirement for Alexa Skills, they support all sorts of uses, and are much more open to submissions.
The Others
There are even more Voice assistants out there, such as Samsung’s Bixby, Microsoft’s Cortana, and the popular open-source voice assistant Mycroft. All three have a reasonable following, but are still in the minority compared to the three Goliaths of Amazon, Google and Apple.
Building On Amazon Alexa
Amazons Ecosystem for voice has evolved to allow developers to build all of their skills within the Alexa console, so as a simple example, I am going to use its built-in features.
Alexa deals with the Natural Language Processing and then finds an appropriate Intent, which is passed to our Lambda function to deal with the logic. This returns some conversational bits (SSML, text, cards, and so on) to Alexa, which converts those bits to audio and visuals to show on the device.
Working on Amazon is relatively simple, as they allow you to create all parts of your skill within the Alexa Developer Console. The flexibility is there to use AWS or an HTTPS endpoint, but for simple skills, running everything within the Dev console should be sufficient.
Let’s Build A Simple Alexa Skill
Head over to the Amazon Alexa console, create an account if you don’t have one, and log in,
Click Create Skill then give it a name,
Choose custom as your model,
and choose Alexa-Hosted (Node.js) for your backend resource.
Once it is done provisioning, you will have a basic Alexa skill, It will have your intent built for you, and some back end code to get you started.
If you click on the HelloWorldIntent in your Intents, you will see some sample utterances already set up for you, let’s add a new one at the top. Our skill is called hello world, so add Hello World as a sample utterance. The idea is to capture anything the user might say to trigger this intent. This could be “Hi World”, “Howdy World”, and so on.
What’s Happening In The Fulfillment JS?
So what is the code doing? Here is the default code:
This is utilizing the ask-sdk-core and is essentially building JSON for us. canHandle is letting ask know it can handle intents, specifically ‘HelloWorldIntent’. handle takes the input, and builds the response. What this generates looks like this:
We can see that speak outputs ssml in our json, which is what the user will hear as spoken by Alexa.
Building For Google Assistant
The simplest way to build Actions on Google is to use their AoG console in combination with Dialogflow, you can extend your skills with firebase, but as with the Amazon Alexa tutorial, let’s keep things simple.
Google Assistant uses three primary parts, AoG, which deals with the NLP, Dialogflow, which works out your intents, and Firebase, that fulfills the request, and produces the response that will be sent back to AoG.
Just like with Alexa, Dialogflow allows you to build your functions directly within the platform.
Let’s Build An Action On Google
There are three platforms to juggle at once with Google’s solution, which are accessed by three different consoles, so tab up!
Setting Up Dialogflow
Let’s start by logging into the Dialogflow console. Once you have logged in, create a new agent from the dropdown just below the Dialogflow logo.
Give your agent a name, and add on the ‘Google Project Dropdown’, while having “Create a new Google project” selected.
Click the create button, and let it do its magic, it will take a little bit of time to set up the agent, so be patient.
Setting Up Firebase Functions
Right, now we can start to plug in the Fulfillment logic.
Head on over to the Fulfilment tab. Tick to enable the inline editor, and use the JS snippets below:
index.js
'use strict';
// So that you have access to the dialogflow and conversation object
const { dialogflow } = require('actions-on-google');
// So you have access to the request response stuff >> functions.https.onRequest(app)
const functions = require('firebase-functions');
// Create an instance of dialogflow for your app
const app = dialogflow({debug: true});
// Build an intent to be fulfilled by firebase,
// the name is the name of the intent that dialogflow passes over
app.intent('Default Welcome Intent', (conv) => {
// Any extra logic goes here for the intent, before returning a response for firebase to deal with
return conv.ask(`Welcome to a firebase fulfillment`);
});
// Finally we export as dialogflowFirebaseFulfillment so the inline editor knows to use it
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
Now head back to your intents, go to Default Welcome Intent, and scroll down to fulfillment, make sure ‘Enable webhook call for this intent’ is checked for any intents your wish to fulfill with javascript. Hit Save.
Setting Up AoG
We are getting close to the finish line now. Head over to the Integrations Tab, and click Integration Settings in the Google Assistant Option at the top. This will open a modal, so let’s click test, which will get your Dialogflow integrated with Google, and open up a test window on Actions on Google.
On the test window, we can click Talk to my test app (We will change this in a second), and voila, we have the message from our javascript showing on a google assistant test.
We can change the name of the assistant in the Develop tab, up at the top.
So What’s Happening In The Fulfillment JS?
First off, we are using two npm packages, actions-on-google which provides all the fulfillment that both AoG and Dialogflow need, and secondly firebase-functions, which you guessed it, contains helpers for firebase.
We then create the ‘app’ which is an object that contains all of our intents.
Each intent that is created passed ‘conv’ which is the conversation object Actions On Google sends. We can use the content of conv to detect information about previous interactions with the user (such as their ID and information about their session with us).
We return a ‘conv.ask object’, which contains our return message to the user, ready for them to respond with another intent. We could use ‘conv.close’ to end the conversation if we wanted to end the conversation there.
Finally, we wrap everything up in a firebase HTTPS function, that deals with the server-side request-response logic for us.
Again, if we look at the response that is generated:
We can see that conv.ask has had its text injected into the textToSpeech area. If we had chosen conv.close the expectUserResponse would be set to false and the conversation would close after the message had been delivered.
Third-Party Voice Builders
Much like the app industry, as voice gains traction, 3rd party tools have started popping up in an attempt to alleviate the load on developers, allowing them to build once deploy twice.
Jovo and Voiceflow are currently the two most popular, especially since PullString’s acquisition by Apple. Each platform offers a different level of abstraction, so It really just depends on how simplified you’re like your interface.
Extending Your Skill
Now that you have gotten your head around building a basic ‘Hello World’ skill, there are bells and whistles aplenty that can be added to your skill. These are the cherry on top of the cake of Voice Assistants and will give your users a lot of extra value, leading to repeat custom, and potential commercial opportunity.
SSML
SSML stands for speech synthesis markup language and operates with a similar syntax to HTML, the key difference being that you are building up a spoken response, not content on a webpage.
‘SSML’ as a term is a little misleading, it can do so much more than speech synthesis! You can have voices going in parallel, you can include ambiance noises, speechcons (worth a listen to in their own right, think emojis for famous phrases), and music.
When Should I Use SSML?
SSML is great; it makes a much more engaging experience for the user, but what is also does, is reduce the flexibility of the audio output. I recommend using it for more static areas of speech. You can use variables in it for names etc, but unless you intend on building an SSML generator, most SSML is going to be pretty static.
Start with simple speech in your skill, and once it is complete, enhance areas which are more static with SSML, but get your core right before moving on to the bells and whistles. That being said, a recent report says 71% of users prefer a human (real) voice over a synthesized one, so if you have the facility to do so, go out and do it!
In Skill Purchases
In-skill purchases (or ISP) are similar to the concept of in-app purchases. Skills tend to be free, but some allow for the purchase of ‘premium’ content/subscriptions within the app, these can enhance the experience for a user, unlock new levels on games, or allow access to paywalled content.
Multimodal
Multimodal responses cover so much more than voice, this is where voice assistants can really shine with complementary visuals on devices that support them. The definition of multimodal experiences is much broader and essentially means multiple inputs (Keyboard, Mouse, Touchscreen, Voice, and so on.).
Multimodal skills are intended to complement the core voice experience, providing extra complementary information to boost the UX. When building a multimodal experience, remember that voice is the primary carrier of information. Many devices don’t have a screen, so your skill still needs to work without one, so make sure to test with multiple device types; either for real or in the simulator.
Multilingual
Multilingual skills are skills that work in multiple languages and open up your skills to multiple markets.
The complexity of making your skill multilingual is down to how dynamic your responses are. Skills with relatively static responses, e.g. returning the same phrase every time, or only using a small bucket of phrases, are much easier to make multilingual than sprawling dynamic skills.
The trick with multilingual is to have a trustworthy translation partner, whether that is through an agency or a translator on Fiverr. You need to be able to trust the translations provided, especially if you don’t understand the language being translated into. Google translate will not cut the mustard here!
Conclusion
If there was ever a time to get into the voice industry, it would be now. Both in its prime and infancy, as well as the big nine, are plowing billions into growing it and bringing voice assistants into everybody’s homes and daily routines.
Choosing which platform to use can be tricky, but based on what you intend to build, the platform to use should shine through or, failing that, utilize a third-party tool to hedge your bets and build on multiple platforms, especially if your skill is less complicated with fewer moving parts.
I, for one, am excited about the future of voice as it becomes ubiquitous; screen reliance will reduce and customers will be able to interact naturally with their assistant. But first, it’s up to us to build the skills that people will want from their assistant.
Market research can be the holy grail of customer insights, revealing motivations behind purchase decisions, behavioral patterns, likes, and dislikes. Information like this can help you make informed decisions about creating new products or services, entering new markets, and more.
Done right, market research can be extremely valuable. But not planning properly or taking the wrong approach with market research can tank your efforts and flush valuable marketing dollars down the drain. We created this in-depth guide to help you avoid this unfortunate situation. Keep reading to learn how to do market research the right way — in four easy-to-digest chapters. But before the synopsis, let us summarize the basic market research process in 6 steps.
How to conduct market research
Identify the problem. The problem may be a dilemma you’ve faced in the past and want to avoid facing again or it may be the need for a new revenue-generating opportunity.
Establish your budget. Determine how much you’re willing to spend to get the answers you need.
Design the research. Decide on factors such as sample size, questions, and method.
Collect the data. How you collect market research data will depend entirely on the research method you chose.
Analyze and present data. Whatever analysis technique you use, present your findings in a way that clearly and accurately communicates the takeaways.
Take action. Once you’ve obtained the information you were looking for, take appropriate action.
Chapter synopsis
Chapter 1: Introduction
Chapter 2: What is market research? Start out with a solid foundation by understanding what market research is, what it entails, and why it’s important. Bonus: Get tips on creating a buyer persona.
Chapter 3: The market research process. How does the market research process work? Find out in this chapter, which walks through the six-step research process, from identifying the problem to taking action.
Chapter 4: Market research methods. What methods can you use to find answers to your burning questions? There are plenty, but we walk through five frequently used methods, when it’s best to employ them, and pitfalls to watch out for.
Chapter 5: Market research strategies. When you need to round out your market research efforts or gain some quick insights, these market research strategies are great options.
Remember to bookmark this guide for later reference. Market research can be a complex topic, and as your needs change you may need a refresher on approaches or methods you haven’t used before.
What is market research?
Market research is the process of gathering information about a target audience, typically your customers. The purpose is to understand their wants, needs, and preferences; you can then use that data to benefit your organization in a variety of ways.
Why is market research important? As a critical part of business strategy, market research can inform your decisions on a number of things, including
Future product offerings. What types of products or additional features might customers like to see?
Current marketing materials. Are they effective, or can they be tailored differently to achieve better results?
Service structures. What can you change to improve the customer experience?
Business processes. How could you change them to achieve better outcomes for customers?
Gathering insights directly from customers gives you the opportunity to check your assumptions. Even the most talented of employees can’t read customers’ minds, which is why asking customers for their input is essential to understanding them.
Market research consultant Annalisa Tammaro adds that conducting market research lowers your risk of making the wrong business decision, such as introducing a new product your customers won’t like: “The importance of market research lies in getting customer feedback on a specific subject early on to ensure you’re heading down the right path. Your research findings then provide a key reference point for all related decisions.”
Market research comes in two flavors: primary research and secondary research. We cover these research types below, along with an important foundational component of market research — the buyer persona.
Primary market research
In short, primary market research is research you either conduct yourself or hire someone to conduct for you for a specific purpose. What makes this type of research primary is that you or your designee are going straight to the source to gather the information you want. If you’ve ever put together a focus group, conducted an interview, or sent out a survey to your customers, you’ve done primary research.
For example, if you’re thinking about redesigning one of your products, you’ll want input from customers regarding what they like and don’t like about it. This will give you a sense of what aspects can be improved during the redesign to make the product more appealing. Seeking input from these customers through a survey or similar method would be considered primary market research.
Secondary market research
In contrast, secondary market research is the process of compiling research that’s already been conducted and analyzed, so you can use it for your benefit. Unlike primary research, secondary research may not have been performed for the same purpose for which you’re using it.
Examples of secondary research include publicly available studies by government agencies, for-purchase studies by research firms like Nielsen and Gartner, reports by trade associations, and data collected by competitors. “Even web searches for interesting statistics can be considered secondary research,” explains Tammaro.
Consider the previous example of wanting to redesign one of your products. Instead of expending the effort of setting up a research study of your own customers, you may purchase a completed study using participants that align with your typical customer persona. Depending on the purpose of the purchased research, you may not get answers to specific questions, but it could still provide tangential insights that inspire you to create a completely new type of product.
The key to market research: Buyer personas
A buyer persona is a collection of demographics, behavior patterns, motivations, quotes, goals, and other identifying aspects that represent your ideal customer. Buyer personas are a critical part of market research because they provide a basis for tailoring your research questions and qualifying the input you receive from research participants.
Tammaro provides a few tips on building a buyer persona:
Identify patterns from available customer data. For example, if you run an e-commerce store, review visitor demographics and their buying behavior to determine commonalities.
Segment your customers into smaller groups. Not all customers are alike, especially if you have a broad assortment of products. You may need to create multiple buyer personas based on characteristics like age, income, or personality traits.
Use multiple research methods. With a survey, you can easily reach many customers and identify broad customer demographics or concerns. However, other methods like one-on-one interviews can provide a deeper perspective and unearth emotional motivators you can use to build an in-depth buyer persona.
Now that we’ve introduced you to market research as a concept, let’s move into how the market research process works.
The market research process
Conducting market research can provide you with a wealth of knowledge and information about your customers, but only if you take a thoughtful approach. You can’t simply come up with a few questions off the cuff and send them out. Effective planning and execution are essential. Start by outlining a clear market research process like the one laid out below by Holly Brown, CEO of Boston Research Services.
Step 1: Identify the problem
Your market research problem will differ from those of other businesses, and even in your own business, it will likely change over time. The problem may be a dilemma you’ve faced in the past and want to avoid facing again, or it may be the need for a new revenue-generating opportunity.
Here are a few examples of potential business problems you can address through market research:
Customers, prospects, and the general public have a negative perception of your brand.
You’re confused about exactly what drives customers to purchase your products or services (or, more generally, the types of products and services you provide).
You believe there’s more potential profit in your products.
You’re unsure about how customers will respond to an upcoming ad campaign.
Once you’ve identified your overarching business problem, Brown recommends coming up with two or three related objectives to explore. Limiting your objectives “helps you avoid respondent fatigue from asking too many questions, but also ensures you don’t develop tunnel vision.”
Step 2: Establish your budget
Market research always has a cost. You must determine how much you’re willing to spend to get the answers you need. The larger and more complex the problem, the more you should budget, even if you’re doing everything in house.
If you’re willing to let a market research firm do the legwork, Brown recommends contacting three firms for quotes. You’ll need to provide your criteria and audience demographics, among other aspects.
Ensure the quotes you receive include the programming of the survey; field work, such as hosting interviews and gathering data; data analysis; and delivery of results. Be prepared for extra fees if you require additional components, such as regression analysis or segmentation, which are more complex statistical methods for analyzing data.
Step 3: Design the research
This step is the “how” of the market research process, when you decide on factors such as
Sample size and characteristics. Choosing the right sample size depends on a number of factors. For one, are you reaching out to current customers (which will be limited), a representative sampling of customer look-alikes, or a broad demographic? In addition, your topic can limit the number of available participants. For example, semiconductors are more niche than TVs, meaning there are fewer participants who can answer questions about them.
Questions. Whatever method you go with, you’ll need to determine exactly what questions to ask and which answer choices to provide, if any. Recall the objectives you set. “If a question doesn’t help achieve one of your objectives, don’t use it,” cautions Brown.
Method. You’ll need to select a mode of delivery for your questions, such as a survey, interview, or focus group. The questions you come up with will help you choose a method. For example, open-ended questions work better in an interview or focus group setting than a survey.
Step 4: Collect the data
How you collect market research data will depend entirely on the research method you chose. For example, if you chose a survey, you can use a robust survey tool to distribute and collect your data for later analysis. If you chose an interview, you may have recordings from participants you’ve transcribed for later review.
Step 5: Analyze and present data
Your market research analysis approach should reflect your chosen method.
Quantitative methods like surveys with closed-ended questions can use techniques such as cluster analysis, which separates objects into specific, exclusive groups that are similar. Qualitative methods like interviews call for techniques, such as analytical induction, where you hypothesize and re-hypothesize the reason for events as you learn about similar events.
Whatever analysis technique you use, present your findings in a way that clearly and accurately communicates the takeaways. This could be in the form of simple statements, tables, graphs, slides, etc.
Step 6: Take action
Once you’ve obtained the information you were looking for, take appropriate action. Your actions will depend on your objectives, but here are a few examples of actions you might take:
Direct your marketing toward a new or different type of customer.
Highlight a specific benefit or feature of your product in marketing campaigns.
Change your product or service’s pricing structure.
In step three, we mentioned selecting an appropriate market research method. In the next chapter, we’ll walk through several widely used methods and when they should be used.
Market research methods
When you’ve identified your problem and established your budget, the next step is to choose the appropriate market research method (sometimes referred to as a market research technique).
Whether you’re gathering quantitative or qualitative data, or a mix of the two, the market research methods below are some of the most frequently ones used to gather key information for decision making.
Focus groups
Market research focus groups are widely used to gather qualitative data. With focus groups, you bring together a small selection of people to ask their opinions or gauge their reactions to a stimulus. The people are typically representative of your customers, and the stimulus is usually one of your products. A moderator leads the session.
Mark McElwain, a market research expert with SRAX, says focus groups are a great way to drill down on a specific topic, such as feelings about a new product. His key recommendation for getting the most out of a focus group: Employ a talented moderator.
According to McElwain, the moderator can make or break your focus group. “Extracting insightful answers from participants takes a certain level of finesse. You have to get people to open up and talk at length, and that takes knowing people and being able to read the room. A great moderator can get insights from people in any focus group, whether it’s one about the Oprah Winfrey Network or Mercedes.”
One thing McElwain says to look out for with focus groups is group think — where one participant’s opinions become so overbearing, they influence the opinions of the rest of the participants. “If a moderator can’t maintain control of the room, one participant can wind up directing the conversation and subsequently skew results.”
Interviews
Unlike focus groups, qualitative interviews offer a more individualized approach to gaining customer insights. And while the moderator (or interviewer) is still important here, your market research interview questions are the most important component of a successful interview.
Pay extra attention to ensure your questions align with your objectives, and that they are open-ended to elicit in-depth responses, whether you’re conducting your interview in person or online.
McElwain says interviews are another useful way to go deep regarding a specific topic, but they are also generally more expensive and less scalable than focus groups. “Like any market research method, the interview has benefits and drawbacks. For example, the interviewee may be more open without the presence of other people, but you’re also only getting a single perspective.”
Surveys
Market research surveys tend to be more quantitative in nature, as most questions are closed-ended, requiring a simple yes or no response, or multiple-choice answer. Surveys are great for reaching a wide audience — think hundreds or thousands of people — because they can be done online and anonymously.
Easy-to-use tools like JotForm help you quickly create, distribute, and collect data for all manner of market research surveys.
Direct observation
Observation market research is qualitative and involves directly observing participants using your product in the “real world” or a representative environment. The purpose is to study customer behaviors that naturally occur in certain contexts surrounding your product to better understand customers.
However, McElwain cautions that observation market research has its issues: “The danger is you only have an experiment group, instead of an additional control group. This makes it impossible to compare results as you would with more scientific observation research.”
Field studies
The market research study (or field study) is a qualitative form of research that encompasses a number of methods requiring in-person interaction. For example, observation, focus groups, and interviews can all be considered field studies in some way. One method that departs from these examples is the in-home usage study.
An in-home usage study is most frequently used to test products. Participants use (and typically keep) your product, documenting their usage over a predetermined time period. For example, you may send participants a new dishwashing soap that they are supposed to use daily. Every day, participants respond to a survey that asks questions about their experience, such as how well the soap performed on tough cleaning jobs.
Now that we’ve covered the methods, let’s get strategic. The next chapter goes into the various strategies you can employ with market research.
Market research strategies
You can perform market research in a number of ways.
While the standard methods of surveying and the like are valuable, there are also unique market research strategies you can employ to gain not only information but different perspectives that can further inform your decision making and even prime your more traditional research methods.
Below we describe several less-structured strategies you can try out today.
Industry publications
Following industry publications that relate to your product or service helps you keep a finger on the pulse of your market — trends, competitor happenings, new problems customers are facing, and shifts in customer demand. These publications can also help identify the right questions to ask in a survey or interview as well as questions to ask internally to improve business processes for better customer outcomes.
In many cases, you can also partner with industry publications to access or purchase their list of readers; you can then try to engage with those people using traditional research methods like surveys.
Competitive assessments
When you want to gain insight about your competitors, competitive assessments offer solid learning opportunities. “They help you understand how competing brands are viewed from a customer’s point of view,” explains George Kuhn, president of Drive Research.
Competitive assessments often include a range of activities to gain a full picture of the competitive landscape:
Research competitors’ websites. Most companies have a collection of white papers, e-books, blogs, brochures, case studies, and other content that showcases their expertise.
Enlist mystery shoppers to make calls and send emails. Mystery shoppers pose as customers to observe and measure competitors’ customer experiences.
Conduct customer interviews. Going straight to the source is often the best way to be in the know. In person, such as at a mall, you may need to get permission before asking for customer feedback about a shopping experience, but it can be worthwhile to get this kind of input.
Kuhn shares an example of an apartment developer who wanted to minimize the risk associated with building a new complex — i.e., Will people rent if we build here?
His firm performed a competitive assessment, inventorying the market and conducting mystery shopping calls to get an idea of the number of unoccupied units, typical amenities offered, square footage ranges, etc. His team also performed a market analysis to see where the population was shifting, how much customers were willing to pay, and what they were looking for in a rental community.
Internet market research
As a tried and true strategy, internet market research can answer many of your questions — whether they’re about competitors or customers. However, despite the ease of conducting internet research and the plethora of information that’s available, Kuhn says this strategy can be problematic.
“For one, you have to be careful with your search terms. Even changing a single word in a phrase can produce significantly different search results. More importantly, knowing which sources to trust is a big issue. Just because a site ‘answers’ your question doesn’t mean the answer was accurate,” Kuhn says.
Social media market research
With the rise in online socialization, social media market research has quickly become a viable way to gain information about customer sentiment. Kuhn says there are two main angles to using social media: using your own or competitors’ social accounts to mine insights, and using your social account as a primary research tool.
“Your social media account gives you great data points to learn more about the people who follow you, which should mostly consist of your customers and prospects,” explains Kuhn. This includes demographic data such as age and location. Meanwhile, reviewing both your account and your competitors’ accounts can tell you what type of content people are responding to, as well as what people are saying about that content or the brand that shared it.
Alternatively, you can use your social media account as a vehicle for other research methods, such as surveys. “You can run ads on social platforms. For example, if you’re a brick-and-mortar retailer, you can target surveys to people living close to your store to gauge whether they’re aware of your presence and, if so, why they haven’t visited. You can then use their responses to improve your marketing.”
Annalisa Tammaro has over 20 years of market research experience in a variety of industries, with vast knowledge of quantitative and qualitative research methods. Her strengths include management and communication skills, which she combines with her ability to help others draw critical connections between research results and business opportunities.
George Kuhn
George Kuhn is the president of Drive Research, a market research company in upstate New York. He has 15 years of experience in market research managing both qualitative and quantitative research for brands like FedEx, Google, Samsung, T-Mobile, PBS, and Clorox.
Holly Brown
Holly Brown is the president and CEO of Boston Research Services, a full-service market research firm located in Auburn, Massachusetts. She has 20 years of experience helping companies with their market research needs, from providing sample audiences and fielding their surveys to analyzing their data.
Mark McElwain
Mark McElwain has been in the market research space for over 10 years, working for companies such as E-Rewards (Dynata), Nielsen, FocusVision, and now SRAX. With both domestic and international operations experience, Mark brings a depth of knowledge to all manner of market research engagements.
Every month we roundup the best new portfolios released in the previous four weeks. This month we’re looking back at the whole of 2019, and picking out 19 of our favorites from the last 12 months. There’s a mixture here of colorful and restrained, experimental and expected; the one thing they all have in common is an attention to details that creates an exceptional UX. Enjoy!
WTF Studio
If you’re going to name your business WTF Studio, you need a suitably WTF site. Able Parris is a NY-based creative director who’s more than happy to slap you in the face with colour and motion. What we really loved about this site is that once you’ve scrolled past the anarchic introduction, it’s actually very safe, very clear. Attitude doesn’t have to mean sacrificing UX.
Stereo
Stereo features smooth animation, a beautiful palette, and some really gorgeous type. What makes it stand out is the unusual navigation menu — it scrolls across the center of the screen like an old-style marquee. We also loved its sweeping animation as it transitions from state to state.
Eva Garcia
We weren’t just impressed with the portfolios of design agencies this year. Eva Garcia’s portfolio is a classic example of how to build a portfolio site. It’s brand-appropriate, intuitive to use, and lets the work come to the fore.
Kévin Chassagne
Kévin Chassagne’s site is a great example of a site that delivers excellent layout, and awesome animation, without relying on JavaScript. The JavaScript here is used for a few details, but you really lose nothing without it. Everything from the typography, to the colour scheme, to the simple UX are great for a portfolio when you’re potentially browsing hundreds of sites at once.
Nicky Tesla
Nicky Tesla’s portfolio is one of the most original of 2019. It’s a spreadsheet; it doesn’t just look like a spreadsheet, it actually is one; it’s a publicly available spreadsheet on Google, with a domain attached. It’s not the most beautiful portfolio you’ll ever see, but it is daringly committed to its core concept.
Florian Wacker
Florian Wacker’s portfolio features absolutely beautiful typography. This site wowed us back at the start of the year, when minimalism was still de rigueur. As a pitch to design agencies that value good typography, this is almost faultless.
Adam Brandon
More minimalism from the start of 2019 in the form of Adam Brandon’s portfolio. His client list is fairly formidable, with Netflix, Apple, Nike, and Ford in there. The site sensibly takes a step back and lets the work promote itself.
EVOXLAB
Evoxlab is an unusual site for us, in that it has gone out of its way to mimic powerpoint slides, which is bordering on skeuomorphism. Well, kinda. It certainly feels like a slideshow. We’ve included it because it’s really committed to the concept, and in this case it works.
Plug & Play
The agency site for Plug & Play is one of the least challenging sites we’ve seen in 2019. In many ways it verges on cliché, but that’s all intentional, because this site is about a simplified user experience. What’s more we love the way it transitions from dark mode to light, as you scroll.
Athletics
Athletics jumps right into fullscreen video case studies of work for clients like IBM. At that point, if you have the budget, you’re probably sold, but Athletics follows up with a grid of lower-profile, but equally exciting design work.
Revolve Studio
Revolve Studio’s site really stands out not because of the presentation-style user experience, but because it’s built in ASP.NET. It also stands out by not showing any work, which is an unusual approach that has been surprisingly popular over the last year.
Florian Monfrini
Florian Monfrini’s portfolio is an expanded, full screen, collage approach. It fills the space well, and was one of the sites that adopted this approach long before it became fashionable.
Angle2
We love the typography of Angle2. It’s another slideshow-style site, but it’s brought to life by the angles and skew of the typography. Despite the energetic feeling text, and the variety of designs — one per page — it always remains usable.
Florent Biffi
If 2019 was the year of a single effect, it was the year of rippling, liquid-style effects. One of the first we saw was Florent Biffi’s site, with huge, bold typography and a subtle rippling effect over the design.
Bethany Heck
We really loved the semi-brutalist approach of Bethany Heck’s portfolio. It’s just a collection of project titles, and in places the accompanying logos, that lead either to the site being referenced, or to an internal link with delightful typography.
Bold
Bold’s portfolio is a simple presentation with some exceptionally sophisticated details. We loved the way the border expands from the images as you scroll, creating the sense of zooming into a project. It’s a confident and understated portfolio that sells to big names, with big budgets.
Transatlantic Film Orchestra
The Transatlantic Film Orchestra make music for video. Its website opens with calm, dark, monochromatic visuals, and absolutely no auto-play audio, which is exactly the right approach. When we actually chose to play the audio, we loved the UI.
Nick Losacco
Nick Losacco’s site highlights a lot of different skills, not least his typeface design. The whole site relies heavily on bold typography and an acidic red background for its personality.
Versett
Versett’s portfolio is a clean, modern site, that leans towards a one-page approach without ever fully embracing it. It’s easy to scan if you’re a business comparing potential agencies, and we loved the “More+” menu option that herds you towards different options like product design, or launching a new company.
Every week users submit a lot of interesting stuff on our sister site Webdesigner News, highlighting great content from around the web that can be of interest to web designers.
The best way to keep track of all the great stories and news being posted is simply to check out the Webdesigner News site, however, in case you missed some here’s a quick and useful compilation of the most popular designer news that we curated from the past week.
Note that this is only a very small selection of the links that were posted, so don’t miss out and subscribe to our newsletter and follow the site daily for all the news.
PhotoStockEditor: Free HD Images for Commercial Use
UI/UX Design Trends for 2020
Bravo Studio: Free App Builder for Designers
Creative Agency Spends $10,000 on Blank Ads
Neumorphism in User Interfaces
Disney Plus – Quick Wins for a Better Way-finding Experience
After More than 6 Years, IMDb Finally Gets a Redesign
Is it harder or easier to build a website now than 10 years ago? Has the bar gone up or down? I don’t have any data for you, but I can shell out some loosey-goosey opinions.
HTML
HTML5 was the only big HTML change in the last decade, and it wasn’t particularly dramatic. It’s cool it’s the looser variant (instead of getting XHTML3 or something). More compatible this way. Maybe I’ll close my and maybe I won’t. Having better semantic tags (e.g.
) is great. Input types are wonderful. But none of this pushes HTML to be significantly easier or harder.
Same.
CSS
CSS has gotten easier. We use way fewer “hacks” all the time. I can literally feel it. The CSS we write today feels so intentional and direct. 10 years ago I feel like every other element had some kind of weird hack on it, and today, almost none. If CSS feels any harder, I’d wager it’s because the sites we’re building are bigger and more complex so the styling systems for them need to be all the more robust and the dangers of getting it wrong more stark.
Easier.
JavaScript
I’m sure there are strong arguments to be made both ways here. The language, perhaps, with all its recent syntactic innovation… perhaps easier. But what JavaScript is being asked to do, and what we’re doing with it, is so astronomically larger that more difficulty comes along for the ride. It’s similar to CSS in that way, but even more pronounced since we’re not just doing what we were before on a new scale; we’re building entire interfaces with the language in a way we just weren’t before.
Harder.
Domains
I mention this one because it’s such a crucial step in any given person’s ability to go from zero to actually having a website.
I don’t think buying a domain name is any easier. Domain names are a commodity market, so the companies selling you them are selling you them for some other reason, meaning the incentive is very high for them to push other products on you. For someone entirely green, I can imagine the confusion is either high or they don’t know enough for the confusion to settle in yet. Do I buy it through this page builder thing? Do I have to buy it through this page builder thing? Do I need the WHOIS protection? Oh god, what even is DNS? I guess I do want email, right? Or is that like some weird special hosted email? Ughjakd. I’m gonna call it a wash. Nothing has made this any easier or harder in a decade.
Same.
Hosting
There is so much money in hosting it kind of blows my mind that we don’t see deeper innovation here. I might argue it’s a little easier these days. But commodity low-end hosting isn’t terribly different or being any more or less helpful than it was a decade ago. We’re still largely stringing together our own bespoke build and deployment processes like we were 10 years ago.
Large-scale stuff might have seen a lot of innovation, a la AWS, but nobody is going to argue that stuff is anywhere near easy.
The most innovation we’ve seen is from companies like Netlify and Zeit who are looking at the developer experience wholistically from helping you run things locally, to testing builds in staging, to immutable deploys. I’d love to see all hosting companies realize that every single one of their customers needs to get their code onto their platforms and they have a massive opportunity to help us do that directly.
Slightly easier.
How people actually do it
I like thinking about HTML, CSS, and JavaScript. But of course, precious few people actually start with those technologies to build actual websites from scratch. Really they end up being treated as underlying technologies you dabble in amongst a slew of other tech.
You can build a website from just an index.html file. I’d argue more people should. But people reach for more “complete” solutions and customize from there. I know I did. The first websites I ever created were WordPress because it was a whole website in a box (with its own struggles) and I customized it. People still do that today, probably more now than 10 years ago, and I don’t feel like it’s significantly easier or harder. Or they reach for something familiar. I made a one-page index.html site not long ago, only to have it picked up by another developer who turned it into a create-react-app site but otherwise changed nothing. They just didn’t know how to work on it without React.
Or they use WordPress.com, or Squarespace, or Wix, or Shopify, or BigCommerce, or you know what I mean. This isn’t about what people can do, it’s about what people do do. And for most people, these apps significantly lower the bar of creating a website.
So, for the average person, is it easier or harder to go from zero to having some kind of website?
Much easier.
Can people actually do it?
If we’re talking about creating from scratch, it’s interesting to see who feels like they even hold those keys anymore. The whole idea for this post came from a conversation I had with someone who has been a front-end developer and was asked to build a website by a friend. They declined because they didn’t know how.
Chatted with someone who’s been working at a company as a front-end developer for 3 years. Their friend asked them to help build a website, but they had to decline. They didn’t know how.
Some part of that doesn’t surprise me. As I write, the world is awfully full of React-specific developers working on huge sites (partially due to boot camps, partially due to market demand). They understand that very specific ecosystem and are perfectly productive within it, but don’t have a wider understanding of how it all comes together to make the complete site.
Specialists are specialists!
Them: What do you do? Me: I’m a web designer Them: Cool! Can you help me build my website? Me: [laughing] Oh god no, I have no idea how to do that
Another part of me is surprised. You know an index.html file with “Hello, World!” in it can be a website, right? Even React devs are generally highly aware of create-react-app and how that scaffolds out a ready-to-rock site. Tools like Stackbit slap together a JAMstack site for you that can go anywhere. For developers, it seems to be going from zero to website is a heck of a lot easier these days.
If you were starting out as a front end dev in 2020, what would you say is the first thing you would learn and why?
You need to put yourself in a position where it’s your job to create and take care of a website. Even if that feels like a stretch for you early on. Get the domain, get the website on the public internet. Put your name on it. Now you’ve given yourself stakes, and you’ll learn technology because you must make your ideas come to life.
For me, 650 years ago, that was putting up a website for the ol’ college band. We needed a website! That sounded like fun to me, and I managed to struggle through buying a domain, hosting, and putting up a WordPress website. Then, over time, I learned front-end web technologies because I wanted to change up the design, change up the templates, add cool features, etc.
Get yourself a project and learn through the project.
How do you determine what you want to turn into a blog post and what you leave as a simple Tweet?
I usually won’t avoid the tweet. The tweet is usually a good proving ground for the blog post anyway. If nobody cared, eh, maybe not that good of a post. If it does get good engagement, it’s like the conversation around it is useful in the creation of the blog post. Plus, tweets are so easy to kick out the door. Blog posts, for me, on purpose, have a longer schedule that includes editing and scheduling and such.
Here’s an example tweet. Just a silly little UI experiment. I didn’t feel like waiting to blog about it to drop the demo. But from the Twitter thread, I got some interesting technical feedback, info about what parts people were most suprised by, and some other related ideas. That will, hopefully, lead to a much more robust blog post.
Do you have a favorite CSS-Trick, where you were just like “wow”?
I think “scroll shadows” in CSS is one of my favorite CSS tricks of all time. It’s originally by Roman Komarov, but explained and improved by Lea Verou. I saw a tool the other day around the idea by Stefan Judis.
It’s a real mind-bender involving four-layered gradient backgrounds, each positioned, sized, and colored differently, and then behaviorally different regarding scrolling.
It’s not just a neat trick because it has real UX implications. Showing a shadow of where you can scroll is important UX. Consider this story of a recent design update in iOS that led to complete confusion around UI actions hidden behind a place you could scroll to, but had zero affordance on how to get there. (Happens to me all the time in Spotify, for the record.)
What would be your top 3 pieces of quick advice for developers trying to follow a similar path to growing their influence and exposure?
I think writing is literally the only way.
I can’t think of a developer with influence who has that influence for anything other than writing. Or if it’s not writing, then it’s a YouTube channel or some other form of creating public stuff.
How much do you see yourself personally playing with Houdini APIs as they are released? Which API are you most excited about (Painting, Layout, Typed OM, …)?
This super-low level stuff sometimes feels over my head. It’s hard for me to picture the industry implications of stuff like this just by looking at specs, ya know?
To me, it seems the Layout API has the most powerful potential.
What I’m imagining right now is that Houdini doesn’t affect normal day-to-day front-end developers like me that much. I won’t be writing much Houdini code. But I’ll use fancy things that other people create, because it does something useful for me. Just like most people don’t write their own libraries or have published npm packages — they just use them.
What is your favorite thing about working at CodePen and/or CSS-Tricks?
You know what I really like? I like getting into the office every day and having a pretty decent amount of freedom of what I’m going to do that day. I’ll probably have meetings. I’ll probably have some stuff on the ol’ calendar. I’ll probably have some team expectations I’m trying to meet. But I also usually have plenty of time to pursue things that are interesting to me at the moment.
Sometimes I’m in the moment to drill through some emails. Sometimes I want to tinker with some demo that sounds like fun. Sometimes I want to write up a thought or record a video. Sometimes I want to plan something out or document something. Sometimes I want to talk something out with other people or do some pair programming.
I’m fortunate that I’m the boss (lol) and I put myself in that position on purpose so I have that freedom.
What is something that you wish we could add in CSS?
I feel like every time someone asks this we all should take every opportunity to scream Container Queries! until we get them.
The idea is that we should be able to write CSS that says, “When this element is this wide, this CSS should take effect.” And not just width, but whatever media queries we have at the page level already.
I want to write a card component that shuffles itself around based on how wide it is, not how wide the page is, because there isn’t always a direct connection between those two things (e.g. a card component can show up in a narrow sidebar on a large screen, but be full-width on a tablet or something).
Every component can be in a situation like that, so for the love of CSS, let me write media queries scoped to those components. I echo a lot of other people when I saw that if we had this, the vast majority of media queries we write would be these, not page-level.
Do you think it’s worth suggesting a { position: above-fold; }?
I’m not sure I’ve ever made a big fold-based decision once in my career. Not a big fan of that thinking. THERE IS A LINE IN WHICH THIS IMPORTANT MODULE MUST NOT CROSS, haha. Prioritizing the most important stuff to be higher up the page, sure. Websites don’t fold like newspapers.
Plus, we’ve got viewport units now, so if you absolutely need to position something in the top visible viewport area, you can.
Since you’ve been writing blog posts for so long, have you developed a process for writing one?
Sorta! It still feels pretty casual to me (let’s call my writing medium quality), so it’s not like I’m renting a cabin in the wilderness and finding inspiration in the sunsets and cheap whiskey.
I write down every blog post idea that comes to me. I try to keep that list fairly public but I also have a personal list where I can be even sloppier.
I put as much context into those lists as I can, so I can hope to summon up the same emotion that made me write it down in the first place. If I revisit the idea a week later and can’t, it’s probably not a very good idea.
I write up the post with as much context as I can. Light research is typically involved.
We have a lead editor on CSS-Tricks, so it’s reviewed by at least one person before being scheduled.
CSS or CSS-in-JS?
I see a ton of cool stuff happening in CSS-in-JS. I think it solves a lot of interesting problems for certain websites. For example, I very much like the idea of having the option to write styles that are scoped to a component programmatically, and thus are tree-shaken when the component isn’t used automatically.
But the web is a big place, and dare I say most websites aren’t built with JavaScript-powered component models. Thus, CSS-in-JS isn’t necessary or appropriate for a lot of sites.
Although, two things to be clear:
You can’t have CSS-in-JS without CSS. CSS-in-JS is still styles that are applied to elements. It doesn’t absolve you from learning CSS.
The CSS-in-JS landscape is wide. It’s a little hard to talk about so vaguely. Each project in the bucket of CSS-in-JS handles things a bit differently and how the styles are applied to the site is even quite wide. I think it sometimes gets lost in the arguments that some of the approaches literally make a CSS stylesheet that you link up like you would any other CSS — even Sass-produced CSS — which there doesn’t seem to be much argument about anymore.
This seemingly simple task had me scratching my head for a few hours while I was working on my website. As it turns out, getting the current page URL in Gatsby is not as straightforward as you may think, but also not so complicated to understand.
Let’s look at a few methods of making it happen. But first, you might be wondering why on earth we’d even want to do something like this.
Why you might need the current URL
So before we get into the how, let’s first answer the bigger question: Why would you want to get the URL of the current page? I can offer a few use cases.
Meta tags
The first obvious thing that you’d want the current URL for is meta tags in the document head:
I’ve seen it on multiple websites where a link to the current page is displayed next to sharing buttons. Something like this (found on Creative Market)
Styling
This one is less obvious but I’ve used it a few times with styled-components. You can render different styles based on certain conditions. One of those conditions can be a page path (i.e. part of the URL after the name of the site). Here’s a quick example:
Here, I’ve created a styled Layout component that, based on the path, has a different background color.
This list of examples only illustrates the idea and is by no means comprehensive. I’m sure there are more cases where you might want to get the current page URL. So how do we get it?
Understand build time vs. runtime
Not so fast! Before we get to the actual methods and code snippets, I’d like to make one last stop and briefly explain a few core concepts of Gatsby.
The first thing that we need to understand is that Gatsby, among many other things, is a static site generator. That means it creates static files (that are usually HTML and JavaScript). There is no server and no database on the production website. All pieces of information (including the current page URL) must be pulled from other sources or generated during build time or runtime before inserting it into the markup.
That leads us to the second important concept we need to understand: Build time vs. runtime. I encourage you to read the official Gatsby documentation about it, but here’s my interpretation.
Runtime is when one of the static pages is opened in the browser. In that case, the page has access to all the wonderful browser APIs, including the Window API that, among many other things, contains the current page URL.
One thing that is easy to confuse, especially when starting out with Gatsby, is that running gatsby develop in the terminal in development mode spins up the browser for you. That means all references to the window object work and don’t trigger any errors.
Build time happens when you are done developing and tell Gatsby to generate final optimized assets using the gatsby build command. During build time, the browser doesn’t exist. This means you can’t use the window object.
Here comes the a-ha! moment. If builds are isolated from the browser, and there is no server or database where we can get the URL, how is Gatsby supposed to know what domain name is being used? That’s the thing — it can’t! You can get the slug or path of the page, but you simply can’t tell what the base URL is. You have to specify it.
This is a very basic concept, but if you are coming in fresh with years of WordPress experience, it can take some time for this info to sink in. You know that Gatsby is serverless and all but moments like this make you realize: There is no server.
Now that we have that sorted out, let’s jump to the actual methods for getting the URL of the current page.
Method 1: Use the href property of the window.location object
This first method is not specific to Gatsby and can be used in pretty much any JavaScript application in the browser. See, browser is the key word here.
Let’s say you are building one of those sharing components with an input field that must contain the URL of the current page. Here’s how you might do that:
If the window object exists, we get the href property of the location object that is a child of the window. If not, we give the url variable an empty string value.
If we do it without the check and write it like this:
const url = window.location.href;
…the build will fail with an error that looks something like this:
failed Building static HTML for pages - 2.431s
ERROR #95312
"window" is not available during server-side rendering.
As I mentioned earlier, this happens because the browser doesn’t exist during the build time. That’s a huge disadvantage of this method. You can’t use it if you need the URL to be present on the static version of the page.
But there is a big advantage as well! You can access the window object from a component that is nested deep inside other components. In other words, you don’t have to drill the URL prop from parent components.
Method 2: Get the href property of location data from props
Every page and template component in Gatsby has a location prop that contains information about the current page. However, unlike window.location, this prop is present on all pages.
Quoting Gatsby docs:
The great thing is you can expect the location prop to be available to you on every page.
But there may be a catch here. If you are new to Gatsby, you’ll log that prop to the console, and notice that it looks pretty much identical to the window.location (but it’s not the same thing) and also contains the href attribute. How is this possible? Well, it is not. The href prop is only there during runtime.
The worst thing about this is that using location.href directly without first checking if it exists won’t trigger an error during build time.
All this means that we can rely on the location prop to be on every page, but can’t expect it to have the href property during build time. Be aware of that, and don’t use this method for critical cases where you need the URL to be in the markup on the static version of the page.
So let’s rewrite the previous example using this method:
This has to be a top-level page or template component. You can’t just import it anywhere and expect it work. location prop will be undefined.
As you can see, this method is pretty similar to the previous one. Use it for cases where the URL is needed only during runtime.
But what if you need to have a full URL in the markup of a static page? Let’s move on to the third method.
Method 3: Generate the current page URL with the pathname property from location data
As we discussed at the start of this post, if you need to include the full URL to the static pages, you have to specify the base URL for the website somewhere and somehow get it during build time. I’ll show you how to do that.
As an example, I’ll create a tag in the header. It is important to have the full page URL in it before the page hits the browser. Otherwise, search engines and site scrapers will see the empty href attribute, which is unacceptable.
Here’s the plan:
Add the siteURL property to siteMetadata in gatsby-config.js.
Create a static query hook to retrieve siteMetadata in any component.
Use that hook to get siteURL.
Combine it with the path of the page and add it to the markup.
Let’s break each step down.
Add the siteURL property to siteMetadata in gatsby-config.js
Gatsby has a configuration file called gatsby-config.js that can be used to store global information about the site inside siteMetadata object. That works for us, so we’ll add siteURL to that object:
module.exports = {
siteMetadata: {
title: 'Dmitry Mayorov',
description: 'Dmitry is a front-end developer who builds cool sites.',
author: '@dmtrmrv',
siteURL: 'https://dmtrmrv.com',
}
};
Create a static query hook to retrieve siteMetadata in any component
Next, we need a way to use siteMetadata in our components. Luckily, Gatsby has a StaticQuery API that allows us to do just that. You can use the useStaticQuery hook directly inside your components, but I prefer to create a separate file for each static query I use on the website. This makes the code easier to read.
To do that, create a file called use-site-metadata.js inside a hooks folder inside the src folder of your site and copy and paste the following code to it.
Make sure to check that all properties — like title, description, author, and any other properties you have in the siteMetadata object — appear in the GraphQL query.
Use that hook to get siteURL
Here’s the fun part: We get the site URL and use it inside the component.
On Line 3, we import the useSiteMetadata hook we created into the component.
import useSiteMetadata from '../hooks/use-site-metadata';
Then, on Line 6, we destructure the data that comes from it, creating the siteURL variable. Now we have the site URL that is available for us during build and runtime. Sweet!
const { siteURL } = useSiteMetadata();
Combine the site URL with the path of the page and add it to the markup
Now, remember the location prop from the second method? The great thing about it is that it contains the pathname property during both build and runtime. See where it’s going? All we have to do is combine the two:
`${siteURL}${location.pathname}`
This is probably the most robust solution that will work in the browsers and during production builds. I personally use this method the most.
I’m using React Helmet in this example. If you haven’t heard of it, it’s a tool for rendering the head section in React applications. Darrell Hoffman wrote up a nice explanation of it here on CSS-Tricks.
Method 4: Generate the current page URL on the server side
What?! Did you just say server? Isn’t Gatsby a static site generator? Yes, I did say server. But it’s not a server in the traditional sense.
As we already know, Gatsby generates (i.e. server renders) static pages during build time. That’s where the name comes from. What’s great about that is that we can hook into that process using multiple APIs that Gatsby already provides.
The API that interests us the most is called onRenderBody. Most of the time, it is used to inject custom scripts and styles to the page. But what’s exciting about this (and other server-side APIs) is that it has a pathname parameter. This means we can generate the current page URL “on the server.”
I wouldn’t personally use this method to add meta tags to the head section because the third method we looked at is more suitable for that. But for the sake of example, let me show you how you could add the canonical link to the site using onRenderBody.
To use any server-side API, you need to write the code in a file called gatsby-ssr.js that is located in the root folder of your site. To add the link to the head section, you would write something like this:
We require React on Line 1. It is necessary to make the JSX syntax work. Then, on Line 2, we pull data from the gatsby-config.js file into a config variable.
Next, we call the setHeadComponents method inside onRenderBody and pass it an array of components to add to the site header. In our case, it’s just one link tag. And for the href attribute of the link itself, we combine the siteURL and the pathname:
`${config.siteMetadata.siteURL}${pathname}`
Like I said earlier, this is probably not the go-to method for adding tags to the head section, but it is good to know that Gatsby has server-side APIs that make it possible to generate a URL for any given page during the server rendering stage.
If you want to learn more about server-side rendering with Gatsby, I encourage you to read their official documentation.
That’s it!
As you can see, getting the URL of the current page in Gatsby is not very complicated, especially once you understand the core concepts and know the tools that are available to use. If you know other methods, please let me know in the comments!
GraphQL has all kinds of awesome tooling built around it. But like everything on the web, it ultimately comes down to data shootin’ across the ol’ network and responses coming back. If you need to talk to a GraphQL API endpoint, you don’t absolutely have to use some kind of framework or library to make requests against it. As a matter of fact, you can do it pretty cleanly in vanilla JavaScript.
From that page, you can execute queries and see the results. You can also poke into the Network tab in DevTools and see the payload for requests it sends off, and see that it’s just a bit of JSON that is POSTed.
We can make our own JSON in that format too! First, we’ll make it an object in the right format, utilizing template literals to make the GraphQL query look nice (which is actually required because the query syntax is dependent on white-space). Then we JSON-ify it with the native JavaScript API and POST it via the also-native fetch API.