Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9075141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:48:08+00:00 2026-06-16T18:48:08+00:00

I’m building a tracking system in Node and need some help understanding how 3rd

  • 0

I’m building a tracking system in Node and need some help understanding how 3rd parties using the tracking script will connect to the Node app.

Initially I had setup a page to connect to the app using Socket.io but that solution only seems to work if the client side pages are hosted on the Node server. So for example on a 3rd party site they would have:

http://node.appserver.com:8080/tracker.js

That script would collect data from the site then connect to the app via socket.io, but I couldn’t seem to get any response back because the app was listening for a request from an index.html file with in the app itself, not from the tracker.js script.

Here is the flow that I want to run the app through:

http://www.evernote.com/shard/s7/sh/56f88de2-f1c0-470b-9169-c7aca1479037/92b00f81ff86eebd4add6f6f68053a50

The tracker.js would connect using the follow:

$.getScript('/socket.io/socket.io.js', function(data){
  var socket = io.connect('http://node.appserver.com:8080');
  socket.emit('adTracker', 
    { adServer: 'datalunk', zone : 'top_home', referingURL : 'comple.com' } 
  );
});

Then the app looks like this:

var app = require('http').createServer(handler)
  , io = require('socket.io').listen(app)
  , fs = require('fs')

app.listen(8080);

io.configure(function () {
    io.set('authorization', function (handshakeData, callback) {
        if (handshakeData.xdomain) {
            callback('Cross-domain connections are not allowed');
        } else {
        callback(null, true);
        }
    });
});


function handler (req, res) {
  fs.readFile(__dirname + '/index.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }

    res.writeHead(200);
    res.end(data);
  });
}

io.sockets.on('connection', function (socket) {
  socket.on('adTracker', function (data) {
var adRequestData = data;
var pass = ["bigbooks"];
var databaseUrl = "username:password@linus.mongohq.com:10006/node-test";
var collections = ["cmnads"]
var db = require("mongojs").connect(databaseUrl, collections);

db.cmnads.insert({adRequest : adRequestData}, {$set: {password: pass}}, function(err, updated) {
    if( err || !updated ) console.log("User not updated");
    else console.log("User updated");
    });
  });
});

Can someone give me some insight on how I should connect our network sites to the actual Node app?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:48:09+00:00Added an answer on June 16, 2026 at 6:48 pm

    your 3rd party client sites need to include your tracker.js (and they need to include socket.io + jQuery because of your $.getScript).

    another solution would be to load socket.io from a CDN in your tracker.js (should be http://cdn.socket.io/stable/socket.io.js) and remove your jQuery-dependency: your code could then look like this (load socket.io and do your stuff when it is loaded):

    (function(document, onload){
    
      var io = document.createElement('script');
      io.src = "//cdn.socket.io/stable/socket.io.js";
      io.setAttribute('async', 'true');
      if ( typeof onload === 'function') {
        io.onloadDone = false;
        io.onload = function() {
            io.onloadDone = true;
            onload();
        };
        io.onreadystatechange = function() {
            if ( "loaded" === io.readyState && !io.onloadDone ) {
                io.onloadDone = true;
                io.onload();
            }
        };
      }
      // head exists -> append to head, otherwise to body
      (document.getElementsByTagName('head') || document.getElementsByTagName('body'))[0].appendChild(io);
    
    })(document, function(){
      // here socket.io should be ready
      var socket = io.connect('http://node.appserver.com:8080');
      // ...
    });
    

    put this inside your tracker.js, host it somewhere and then your clients could just include the tracker.js:

    <script src="yourhost/tracker.js"></script>
    

    but usually tracking-systems are not build using socket.io (i think socket.io is about 100k compressed, and for a tracking-solution pretty big)

    usually tracking-systems are done by creating an request and sending the variables as parameters.

    on the client:

    var img = new Image();
    img.src = "http://node.appserver.com:8080/tracking.gif?param1=value1&param2=value2";
    

    on the server (host a gif 1×1 px and name it tracking.gif):

    var http = require("http");
    var url = require("url");
    var trackingGif = fs.readFileSync("./tracking.gif");
    http.Server(function (req, res) {
      var params = url.parse(req.url, true)).query;
      res.writeHead(200);
      res.end(trackingGif, "binary");
    });
    

    hope it helps a bit. hint: all my code is untested, but should it should be clear what i mean.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am using JSon response to parse title,date content and thumbnail images and place
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a small JavaScript validation script that validates inputs based on Regex. I
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.