👋, In August, we launched a novel approach to a marketing site with ask.edgarallan.com. Since then, we've been focused on determining whether we built a winner or a loser by refining our data analytics capabilities. So far, the results look promising: check out this update. Alongside ask.ea, we’re also enhancing our data analytics for Slater.app. What does that mean? Over the next several months, we’ll be rolling out updates based on your feedback and user data. Stay tuned—we’ll share our discoveries in future newsletters! -- JS 101: Marketing JavascriptThis week we had a client who wanted to hide or show content based on where the user was coming from. This is a common ask from marketers. So, how can we do this? With URL parameters and cookies. Let's dig into the code we wrote: ``` // Function to set a cookie // Function to get a cookie value by name // Main logic to check query parameters and manage cookies if (value === '1' || getCookie("linkedin") === '1') { That code block may be a little overwhelming so let's break it down: 1. Retrieving Query Parameters We can write a getParam function that uses the URL interface to extract query parameters safely. This avoids potential issues with manual string parsing. ``` The URL Constructor creates a URL object to access its searchParams property. searchParams.get: Retrieves the value of a parameter by its name. 2. Setting Cookies The setCookie function creates a cookie with an optional expiration time. ``` The encodeURIComponent encodes the cookie value to ensure it’s URL-safe. 3. Getting Cookies The getCookie function retrieves the value of a specific cookie by its name. ``` split(‘; ‘) splits all cookies into an array of key-value pairs. find finds the cookie that starts with the specified name. The Optional Chaining (?.) safely handles cases where the cookie is not found. 4. Code Logic The main block checks if the `linkedin` query parameter or cookie is set to 1. If true, it removes the first .container element and sets a cookie. ``` The querySelector selects the first matching .container element. This code showcases best practices for:
You now have a robust solution for managing query parameters and cookies in your JavaScript projects. Let us know if it is useful! Happy coding! 🤙 the Slater Team If Slater helps you create better websites, please support the team behind it.
|
Slater resources, updates and community activity
The team behind Slater would like to wish you a Merry Christmas and a happy New Year! 🎄🎅🎁 Get the Santa ASCII art: https://slater.app/projects/11431/pages/27608 Happy coding! 🤙 the Slater Team If Slater helps you create better websites, please support the team behind it. Become a Pro Slater User
Earlier this year, we built figdam.com. It is currently used by several of our clients to host files and watermark PDFs. We’d like to bring this file hosting functionality to Slater users. With that in mind, where do you currently store files that Webflow doesn’t support? Would this feature be useful to you? What file hosting features do you need? Let us know. JS 101: File types File storage? Javascript? Let's consider all of the different file types that you could host and then retrieve and...
Hi, Just a reminder that Kendra and Mason will be hosting an EA Office Hours Zoom this Friday, the 13th (spooky…) to chat about topics relating to Chapter 1: Sales for Creative Types. Sign up if you can make it, and bring your questions. Let’s get past any lingering sales ick together. Register to join us this Friday, 12/13 here. Also, if you can’t make it this week, we’re thinking about doing it again next Friday, 12/20 as well, if anyone is game? To ring in the holiday break, we’ll chat...