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 9085175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:10:54+00:00 2026-06-16T21:10:54+00:00

I want to provide a javascript snippet code (kinda like google analytics) to my

  • 0

I want to provide a javascript snippet code (kinda like google analytics) to my clients which will use the code on their website and track visit duration on their website. I want to use cookies for this.

My only question is what’s the best way to implement? A few options I have in mind:

  1. Should I set cookies from PHP (which is going to be sitting on my
    domain) and will that be considered as 3rd party cookie?
  2. Or do I have to set a cookie from Javascript since it will be client
    side loaded from my site?
  3. Or would be the best way to set cookies with javascript and access
    them with PHP?
  • 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-16T21:10:55+00:00Added an answer on June 16, 2026 at 9:10 pm

    If you set the cookies in JavaScript the domain of the cookie is going to be the website’s domain and not your domain. So that information is not available when doing something like.

    <script src="http://example.com/tracking-js.php"></script>
    

    With other words, that won’t work.

    Instead you would need to send the clients information to your webservice using AJAX or (how google does it) by loading a blank images.

    There are a lot of parameters that are available in JavaScript, but not send to the server (not in $_SERVER). Google adds that information as GET parameters.

    However, if you don’t really need that data, the easiest ways is to include your script as image on the client’s website.

    <img src="http://example.com/tracking.php" />
    

    $_SERVER['HTTP_REFERRER'] will be the URL of the page where the script is included.
    Be sure to set the Content-Type to 'image/gif' and output a blank 1px gif.

    When using AJAX, please be aware that you’ll need to use CORS, which means setting the Access-Control-Allow-Origin response header.

    Note that using AJAX without jQuery can be a pain. Since you don’t care about the response, creating a tracking image (using javascript) is probably your best option. Read this article on the basics how to implement that.

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

Sidebar

Related Questions

I want to create a website which will serve more like a web-application. There
I want to provide a piece of Javascript code that will work on any
I want to provide a virtual webcam via DirectShow that will use the video
Possible Duplicate: How to use Google Analytics with Phonegap without a plugin? I want
I want to provide my clients a simple code to insert and get my
I want to provide a button which cancels the present task, Let's say I
I want to provide a custom Batcher for Hibernate to use (for this reason:
I want to provide javascript editing with highlighting in my web page. I am
I have javascript validation code, now I want to prevent . ; , `
I'm writing an HTML5 Game Development Javascript framework and I want to provide the

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.