I recently launched a new campaign for Lord Huron’s upcoming album The Cosmic Selector Vol. 1 which utilizes NFCs. In this campaign, we gave fans NFC powered coins that allowed them to one free play of clips of the new album on a virtual jukebox located at cosmicselector.com. As it turns out, this was also the first time I’ve used NFC chips for a marketing campaign. If you aren’t aware, NFC stands for Near Field Communication and it typically takes the form of a chip that is integrated into a physical object. When a mobile device is near the chip, it communicates with it and some sort of action takes place. Some folks might add an NFC chip to a tag on a piece of merch and when the device reads it, it might take them to the artist website. In fact, this idea of embedding a URL is one of the most common usages of NFCs and it served as the foundation for our Lord Huron campaign. Yes, we added a URL to each NFC but each URL was in fact, unique to the coin. This allowed us to identify individual coins and know whether or not they were “spent.” Individually writing thousands of NFC chips can be a tedious task but I found a web based solution in the Web NFC API.
Web NFC API
If you just have a few NFC chips to write, you can use an app like NFC Tools to do it. However, if you’re trying to create thousands of chips with unique urls, you’ll need a better workflow or an army of interns. For our campaign, I knew we would have a database of coins to keep track of all coins that were “minted” as part of our campaign, their appearance, and their current “spent” status. I envisioned a workflow that allowed me to mint a new coin in the database and write the associated coin URL onto an NFC chip in one go. By utilizing the Web NFC API which is only available for Android, I was able to do this. There’s some really good documentation on the Chrome Developers blog but let’s look at a few high level functions. First, in order to read an NFC, we must initiate an `NDEFReader()` instance, scan the chip, and listen for the read event.
// Initialize reader
const ndef = new NDEFReader()
// Scan chip
ndef.scan().then(() => {
// On read
ndef.onreading = event => {
// Log
console.log(event)
}
})
By analyzing the read event, I could check to see if an NFC was already associated with a coin and prevent creation of duplicates. This was done by looking for URL records on the NFC and seeing if a Cosmic Coin URL was already on it. NFCs allow you to write all sorts of records, including plain text, but a URL record made the most sense for our campaign. If a coin URL was not associated with the NFC, I would create a new coin in my database and write the new coin’s URL to the NFC.
// Write url
await ndef.write({
records: [{
recordType: "url",
data: “https://www.cosmicselector.com/coins/123”
}]
}, {
overwrite: false,
signal: controller.signal
})
It took a little bit of debugging but once I got this workflow functioning properly, I was able to mint a unique NFC coin in a matter of seconds.
Database Attributes
In addition to keeping track of whether or not a coin was used to play the jukebox, we also use our database to keep track of what type of coin it is. We researched many ways to produce our Cosmic Coins including PLA, resin, wood, clay, and metal. I wanted to make sure these unique attributes were stored in the database so I could visualize each coin appropriately when they were scanned. So, for example, if a fan was provided with a red glow-in-the-dark PLA 3D printed coin, it would appear as a red glow-in-the-dark coin on the site. Pretty cool. It is through this marriage of unique URL and database entry that we can track and evolve the data of each coin. Perhaps we want to provide fans with the ability to redeem more plays in exchange for accomplishing specific tasks. With this setup, we can achieve that.
Scanning the Future
Technically, I could have built NFC scanning right into the Cosmic Selector web app and I may have been able to avoid writing unique URLs to each NFC chip and instead simply read the NFCs unique ID. However, as I mentioned earlier, the Web NFC API is only available for Android devices and we’ll need to see when, if ever, Apple iOS would add this functionality. You can join me in watching adoption evolve on the compatibility chart. Anyway, I hope this quick look at how we paired the Web NFC API with a database allowed our NFC campaign to feel a bit more personal and evolve with our campaign rather than being a static URL campaign. Who knows what else we have up our sleeves for these Cosmic Coins. Let me know if you have any questions and want to traverse the world of NFCs or 3D Printing in a new campaign.