Giter Club home page Giter Club logo

cookietrackingsample's Introduction

cookie tracking(& CORS) sample

前提条件

  • Java8
  • sbt

サーバーの起動

sbt trackingServer/run

1st party

(予め、s3-ap-northeast-1.amazonaws.comのCookieを消しておく)

  • http://s3-ap-northeast-1.amazonaws.com/opt-tech-magazine-public/cookieSpec/1st_party_tracking.htmlにアクセス
  • localhostのサーバーからのjsが読まれてcookieを作る。
  • jsがサーバーへTrackingIDをtrackingIDというパラメータで送る
  • サーバーは受け取ったら標準出力で内容を確認する。
  • リロードしても同じIDでトラッキングできている。

3rd party

(予め、localhostのCookieを消しておく)

  • http://s3-ap-northeast-1.amazonaws.com/opt-tech-magazine-public/cookieSpec/3rd_party_tracking.htmlにアクセス
  • localhostのトラッキングピクセルを読むときにSet-Cookieが送られる。
  • 次回以降のアクセスの時にCookieが送られる。
  • サーバーは受け取ったら標準出力で内容を確認する。

no pre flight

  • http://s3-ap-northeast-1.amazonaws.com/opt-tech-magazine-public/cookieSpec/ajax_no_pre_flight.htmlにアクセス
  • htmlのajaxの中で外部ドメインへのapplication/x-www-form-urlencodedのリクエストを出しているので、pre flightなし。
  • POSTリクエストを投げる
  • 処理されて文字列が返ってくるので、それをajaxのcallbackで処理する。

pre flight

  • http://s3-ap-northeast-1.amazonaws.com/opt-tech-magazine-public/cookieSpec/ajax_pre_flight.htmlにアクセス
  • htmlのajaxの中で外部ドメインへのapplication/jsonのリクエストを出しているので、pre flightが走る
  • サーバ側でOPTIONSメソッドに対して対象ドメインを許可する。
  • pre flightが通ったので、改めてPOSTリクエストを投げる
  • 処理されて文字列がブラウザに返ってくる。
  • ヘッダの情報から、ブラウザで処理しても問題ないと判断してjsが処理する。ここではalertの文言を出す。

pre flight2

  • http://s3-ap-northeast-1.amazonaws.com/opt-tech-magazine-public/cookieSpec/ajax_pre_flight2.htmlにアクセス
  • htmlのajaxの中で、独自ヘッダ(X-Requested-With)を付けて外部ドメインへリクエストを出しているので、pre flightが走る
  • サーバ側でOPTIONSメソッドに対して対象ドメインを許可する。
  • pre flightが通ったので、改めてPOSTリクエストを投げる
  • 処理されて文字列がブラウザに返ってくる。
  • ヘッダの情報から、ブラウザで処理しても問題ないと判断してjsが処理する。ここではalertの文言を出す。

cookietrackingsample's People

Contributors

shibatako avatar uryyyyyyy avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

soranaoya

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.