Building email tracking for open rate and geo analytics with JavaScript? - javascript

As a project, I want to learn how to create an email tracker that generates a unique pixel, tracks open rates in JavaScript (MeteorJS).
Does anyone have any resources I can look into to accomplish this? I know ToutApp does this in PHP and found similar tutorials in PHP but nothing in JS.
Cheers!

Use Iron:Router's server-side routing to track when a user clicks on something like /emails/ew45gf23. The ID in the URL could be the _id from the collection that stores all the emails sent, e.g. EmailsSent.findOne({_id: _id})
Router.route('/emails/:_id', function () {
var emailClicked = EmailsSent.findOne({_id: _id});
... do whatever you need to with the tracking ...
this.response.end('email click received\n');
}, {where: 'server'});

Related

How should i send sensible data using JSON?

im making a webservice in JSON to get the user data. for example i pass the user id and get the address of that user or i pass the user id and i get his favorites.
for example:
<script>
$.post('http://www.example.com/webservices/get-address.php', {
userid: "13"
}, function(data) {
$.each(data, function(index) {
alert(data[index].address);
});
}, "json");
</script>
but anyone could change the userid: 13 for userid:14 and get the address of other user.
(i cant use PHP on Mobile APPs so i cant use $_SESSION['id'], i will use localstorage to store the user id)
maybe i should mask the user id with a md5() so they cant guess the "user id" of other users?
which is the correct way to do it?
You need a session cookie. They are negotiated when you visit and log in and are trackable. Also, you should use ssl to avoid sniffing of data.
You need to track your session id at the server end somewhere and link it to the user, so if they ask for a user they aren't allowed to see, you return a 4xx code informing them that they aren't allowed to access that resource.
You could use a tripcode as some anonymous boards do, but then you're more limited to providing the facility to see groups of people etc.

Twilio JS Library

I am currently using the Python helper and Js library for Twilio. I am having a hard time determining how I can I be able to determine if my user is online or not. I know a function for js library containing about Twilio.Device.presence. It was successfully showing all the online user. But how can I determine if the user I am calling currently is online?
In the field number is where I am going to call:
<input type="text" id="number" name="number"
placeholder="Enter a phone number or client to call"/>
In this function:
Twilio.Device.presence(function (pres) {
if (pres.available) {
// create an item for the client that became available
$("<li>", {id: pres.from, text: pres.from}).click(function () {
$("#number").val(pres.from);
call();
}).prependTo("#people");
} else {
// find the item by client name and remove it
$("#" + pres.from).remove();
}
});
The pres.from is the user that are online. How can I be able to for loop on it and check if the data in the number field is same.
Or how can I pass from the function to my views?.
Thanks for the help.
Twilio evangelist here.
A simple way to do this would be to remove the click handler from the <li> element when you detect that the available property of a client has changed to false. That way your users would not be able to initiate a call to that client.
You could also visually show the client state by altering the elements style based on the value of the available property.
Another option would be to remove the entire <li> when the client goes offline so users would not even see the client name.
If you want to keep track of both all online and offline clients, then I think you will need to keep some state on the client that tracks a list of online/offline clients. A simple way to do this would be to use an array of client names. As clients come online you can add their name to this array and as they go offline you remove them from the array.
Hope that helps.

Redirect from JavaScript

I'm working on an internal web app and we are using secure query string keys generated server side for some simple security to prevent users from accessing pages they haven't been given access to. The page I am currently working on grabs data via AJAX calls and renders it in a table on the page. Each row has an edit button that will take the user to an edit page with more information, with the id of the row kept in the query string. Since every row id is unique, the key for every edit page will be unique to that row-user combination.
My problem is that I need to be able to get these secure query string keys from the server in some way that allows the JavaScript to redirect the user. I can't move the key generator client side because that opens up the possibility of users generating their own keys for pages they don't have permission to visit. And similarly I can't expose the generator in a web service.
Basically what this boils down to is I am stumped in finding a way to send data from the client to the server in order to generate a secure key and then redirect the user to the new page.
Not exactly sure if I am being 100% clear but I'll edit this as questions come in.
Your question is a little unclear, but PageMethods might work for this:
[WebMethod]
public static string GetSecureID()
{
return "Secure";
}
clientRedirectSecure = function() {
PageMethods.GetSecureID(onSuccess, onFailure);
}
onSuccess = function(result) {
window.location.href = "somepage.aspx?id=" + result;
}
onFailure = function(error) {
alert(error);
}
Here's an article that discusses PageMethods:
http://blogs.microsoft.co.il/blogs/gilf/archive/2008/10/04/asp-net-ajax-pagemethods.aspx

Syncing contacts with google contacts using contacts javascript api

Hello I have a web portal and people would share there email id's. I would to add the sync with google contacts. I am using javascript api for that, but facing lot of problems. I tried the example code provided by google http://code.google.com/apis/contacts/docs/1.0/developers_guide_js.html#Interactive_Samples
First I need to authenticate users to access there gmail id, i used this code
var contactsService;
function setupContactsService() {
contactsService = new google.gdata.contacts.ContactsService('exampleCo-exampleApp-1.0');
}
function logMeIn() {
var scope = 'https://www.google.com/m8/feeds';
var token = google.accounts.user.login(scope);
}
function initFunc() {
setupContactsService();
logMeIn();
getMyContacts();
}
But the problem is I am able to see the google authentication page when I click on the grant access button,I am redirected to same authentication page though I included create contact function and called on click. I am not able to figure how to proceed further and send contact details dynamically to gmail.
Kindly help me out
The solution for this problem what I followed was I created a iFrame and adding all the javascript and HTML inside that iframe and place that iframe in the mail page.

JavaScript OAuth sign in with Twitter

I have to integrate Sign-in-with Twitter in my app as below.
https://dev.twitter.com/docs/auth/sign-twitter
It is browser based app developed in JavaScript
I have been refering google code java script OAuth, but im confused how to use oauth/authenticate and how to get the oauth_token
Can any one please help me out with some samples ?
Problem with this is that anyone who views your page can also now view your consumer key and secret which must be kept private.
Now, someone could write an app that uses your app credentials and do naughty and bad things to the point that twitter and users ban you, and there isnt anything you can do.
Twitter do state that every possible effort must be made to keep these values private to avoid this happening
Unfortunately, there is currently no way to use oAuth in Browser based JavaScript securely.
Check out the Twitter #Anywhere JSDK authComplete and signOut events and callbacks at https://dev.twitter.com/docs/anywhere/welcome#login-signup
twttr.anywhere(function (T) {
T.bind("authComplete", function (e, user) {
// triggered when auth completed successfully
});
T.bind("signOut", function (e) {
// triggered when user logs out
});
});
Use below code in consumer.js and select example provider in index.html drop down list
consumer.example =
{ consumerKey : "your_app_key"
, consumerSecret: "your_app_secret"
, serviceProvider:
{ signatureMethod : "HMAC-SHA1"
, requestTokenURL : "https://twitter.com/oauth/request_token"
, userAuthorizationURL: "https://twitter.com/oauth/authorize"
, accessTokenURL : "https://twitter.com/oauth/access_token"
, echoURL : "http://localhost/oauth-provider/echo"
}
};
Since I was searching for the same thing, trying not to use a custom PHP solution, I came across this very simple integration at http://www.fullondesign.co.uk/coding/2516-how-use-twitter-oauth-1-1-javascriptjquery.htm which uses a PHP proxy that accepts whatever twitter api call you'd like to retrieve from your javascript ..
I'm definitely taking a look at it

Categories