GithubHelp home page GithubHelp logo

poanchen / add-alexa-rank-ifttt Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 74 KB

Keep track of your site's global or country rank in Alexa. Every time a hit to the API, log it into a Google spreadsheet.

License: MIT License

Python 83.84% Shell 16.16%

add-alexa-rank-ifttt's Introduction

add-alexa-rank-ifttt

An IFTTT applets that allow the users to Keep track of their site's global or country rank in Alexa. Every time a hit to the API, log it into a Google spreadsheet.

Loading the first image

This is what it looks like when you just created the applet

Loading the second image

This is what it looks like when it was just added into the Google Sheets (second col is global rank, third col is country, and forth col is the country rank if any)

Why is this useful?

People who own their own site and care about their site ranking, normally, they would just get on to Alexa site multiple times a day and look at the ranking. Some geek people like me might even write a script that does that lol I mean, I am interested in seeing how my site is doing today but I am also interested in seeing how my site is doing in the past 3 months or even a year or more. Currently, a free version of Alexa only provides up to 6 months worth of data for any site with ranking better than a million. Site that records a million and upwards does not even show at all on Alexa beside the ranking for today. As of now, my personal blog site currently ranked at 1,481,428 as global rank and 271,328 in India. As you can see in the site, it has no past data whatsoever because Alexa consider it as lower traffic site. What if somehow I still want to record it? And, not manully but it just records itself and I can come by and check it out anytime. This is why I write this little script that will help me automate all these.

Disclaimer: I am using the free version of Alexa API, http://data.alexa.com, apparently used by Alexa toolbar according to this article. For people who wants more data, please visit Alexa's offical site to learn more about it.

Okay enough of writing! Let's get back to work and I will show you how this thing work.

Getting started

Prerequisites:

  • Python 2.7 or up
  • A remote web server that allows you to run a cron job

Installation

To begin, you first need to create a private applets in IFTTT in this site. Next, you would choose Webhooks as if and Google Sheets as then. So how it works is that our script will first get your site ranking info from the Alexa API, it would then parse the XML and retrieve relevant information. At the end, assuming everything went successful. It will trigger the IFTTT webhook API to add an entry to the Google Sheets. In case you were wondering how you would get your webhook setting, please visit IFTTT site. Thanks to this site. I was looking for it all over the places haha as it was not very obvious to look for in IFTTT.com. (I am planning on writing a blog with full instruction on how to do it, stay tuned. Will be posted on https://poanchen.github.io)

Development environment

Tested on Ubuntu 14.04.X LTS server but theoretically should work on OS X as well.

Usage

You can simply clone this repo to get the full code. Next, you want to change the config file in order to work with your own settings,

import os
config = {}

# config for your site
config["website"] = "https://poanchen.github.io" # change this to be the site that you would like to check

# config for your ifttt
config["iftttApiEndpoint"] = "https://maker.ifttt.com/trigger/%s/with/key/%s"
config["iftttEventName"] = "add_alexa_rank" # change this to your webhook event name
# you should be able to get your IFTTT maker key from the IFTTT webhook site
config["iftttApiMakerKey"] = os.environ['IFTTTAPIMAKERKEY'] 

# config for alexa site
config["alexaCli"] = 10
config["alexaApiEndpoint"] = "http://data.alexa.com/data"

As you can see, I posted my code on to GitHub. As a result, I do not want to share my IFTTT maker API key to the whole world. Instead, I saved it as an environment variable, only accessble in the server. (so that it will be safe-ish)

In case you were wondering how to set that up, check out my .env.example file,

# Set these environment variables
# For Windows, go to https://superuser.com/questions/949560/how-do-i-set-system-environment-variables-in-windows-10
# For Mac OSX, go to https://stackoverflow.com/questions/7501678/set-environment-variables-on-mac-os-x-lion
# For Linux, go to https://www.cyberciti.biz/faq/set-environment-variable-linux

export IFTTTAPIMAKERKEY=XXXXXXXXXXXXXXXX

Now, all you need to do is to hook this script up with a cron job and you are done.

This is how I set up my cron job.

00 9 * * * cd /path/to/the/add-alexa-rank-ifttt; python getAlexaRank.py >> add-alexa-rank.log; 
date >> add-alexa-rank.log;

This cron job will run the script once a day at 9am sharp. It will also record any log to the add-alexa-rank.log for debugging purposes.

Note

It is possible that the passed-in website does not have rank for both global and country rank. In that case, it will try to get it, if failed, it will simlpy return None in Python. In Google Sheets, that col will simply be empty. (not "" or '' but actually empty lol)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.