How to create a Twitter Lead Generation Card and connect it to Google Spreadsheets?

Back when Twitter started, all you can do was post a 140 character text as a tweet. Later it added a feature where you can add a photo to your tweet. Twitter has come a long way when it added the Cards. Basically you can add rich media and give a great visual mashup to your tweet with the cards. You can read more about twitter cards here.

In this post I would like to write in detail about one particular feature which will be very interesting if you are looking to build an email list using Twitter cards feature which looks like this.

This can be helpful if you are going to conduct an event to which people can sign up directly by clicking a button on Twitter from one of your tweets. May be you want to share some cool information through one of your newsletters to which they can subscribe to. There are many possible scenarios in which you want to build an email list.

Let us look at building a Lead Generation Card in the first half and in the second part we will see how to connect your card to Google Spreadsheets in collecting the data real time directly to your sheet.

Twitter Lead Generation Card with Google Spreadsheets

Part-1: Creating a Twitter Lead Generation Card

Step 1: Creating a Twitter Ads account

Sign in to your Twitter account and access the menu by clicking on your profile image on the top right. Click on Twitter Ads menu. If you haven’t used twitter ads before, you will be prompted for sign up. Just go ahead and fill in the needed currency and country details. Provide your Credit card details. Don’t worry! you will not be charged for entering your details. Once you enter all the details, your ads account will be created.

Step 2: Creating a Card

On your Ads account, you can see an exhaustive menu on the top navigation bar. Click on creatives and select the Cards from the drop down. Input the necessary details like Description, Call to action, Privacy policy URL and Fallback URL. You also need to upload an image with dimensions 800px x 200px. Name your card, accept the terms and create the card. You can enter the Data Settings at a later point of time. If you don’t enter Data settings, your leads will be collected by Twitter which can be downloaded as a CSV file directly. If you think this is more than enough for your purpose you need not connect your card with the Google Spreadsheets.

Step 3: Create a Tweet with the above card

Once you have created your card, you will be landed on the page from where you can compose a tweet with the card you have created. You can either compose a tweet at this stage or just close the browser. You can compose a tweet with this card at any point of time.

Points to be Noted:

Have an appropriate Call to action. Words like “Subscribe”, “Sign up” are prescribed.

Compose a tweet with proper description. Be concise and effective.

If you are not going to promote this campaign, PIN this tweet to your profile so that when people visit your profile they can see your card on top.

Part-2: Connecting Twitter Card to Google Spreadsheet

Google Spreadsheets are one of the most useful apps on web. You can do a whole lot of things with them. They got a feature called Script Editor where you can write JavaScript code and do some cool things on your spreadsheet. Here we are going to use the Scripts feature and connect our Spreadsheet with the twitter card dynamically so that when an user is subscribed to your card, the details will be populated in the spreadsheet in real time.

Step 1: Creating a Spreadsheet

Open Google Sheets and create a blank sheet. Name your sheet and add the menu items to your sheet which are Name, Email, Twitter ID, Twitter Profile Link, Timestamp.

Step 2: Write the code in Script Editor

Access the Tools menu and click on Script editor. Now, you need to write code such that when Twitter posts data to your Sheet, your code should be able to append the data to your sheet. This we will achieve by writing JavaScript functions. Google scripts when deployed will generate a unique URL.

Let’s look what each of these functions do. The first function when runs for the first time sets a variable called “SHEET_ID” with the Sheet ID so that id can be used at a later point of time when we are not accessing the sheet.

The second function is just a simple function for “GET” request. When we access the Script URL from a browser the ‘GET’ function takes over and executes the code inside it.

The third function is a simple function which handles a “POST” request. When twitter posts the data to our Google script URL, the data is encapsulated in an object which we represented by “e”. We access the data inside using JavaScript dot notation as given in the code. Once the data is retrieved, we need to append this to our spreadsheet. For that we will first get the ID of our spreadsheet from the variable “SHEET_ID” and then append the data accordingly to our sheet.

Step 3: Deploy your web app

Once you are done with the above steps, access the Publish menu and click on Deploy as web app. Select the appropriate options as shown in the below picture. Once your app is published you will get an URL to your Script. Copy this Script URL.

Step 4: Run the first function for first time

Once everything is done, select the first function and click on Run button. This makes sure the “SHEET_ID” variable is populated with the Spreadsheet ID. Also, you will be prompted for Authorization. Just go ahead and click continue to complete the process.

Step 5: Data Settings in Twitter Card

Goto your Cards manager and edit your existing card which you have created. Go to the Data Settings and enter the Script URL you have copied into the “Submit URL” field and select the HTTP method as “POST”. Save the card.

That’s all. Your data should now be populating in the Google Spreadsheet whenever a new user subscribes. Twitter provides a nice way to test whether the data is getting posted or not. Try testing the card and check your spreadsheet. If everything works, you should see your own data getting added to the sheet.

Note: One of the common problem with Google Script editor is the changes not getting effected. When you think your changes are not taking place, deploy your app as a new version.

If you face any issues or if you have any other cool hacks related to Twitter cards, do comment below.

Your email address will not be published. Required fields are marked *

Comment

Name *

Email *

Website

Notify me of follow-up comments by email.

Notify me of new posts by email.

Join our Readers

Never miss another great post. Receive free updates on your email!

About Me!

Hey Folks! I am Ram Manohar, author of this website. I am an Independent Digital Analytics and Tag Management Consultant with more than 8 years of experience consulting 15+ Enterprise clients and many small and medium businesses. You can know more about me and connect using below links!