Coder Social home page Coder Social logo

Avoid injection for AMP pages about rack-tracker HOT 9 CLOSED

 avatar commented on June 11, 2024
Avoid injection for AMP pages

from rack-tracker.

Comments (9)

 avatar commented on June 11, 2024 1

Thanks solved

from rack-tracker.

luizeof avatar luizeof commented on June 11, 2024 1

@petervandeput see #110 (comment)

from rack-tracker.

DonSchado avatar DonSchado commented on June 11, 2024

you can set any tracker option dynamically during requests by providing a lambda.

from rack-tracker.

 avatar commented on June 11, 2024

thanks for the quick response, but can you give an example.
When the request is an amp request (mimeType) then it should inject.

from rack-tracker.

DonSchado avatar DonSchado commented on June 11, 2024

not sure about the mime type, but you have access to everything in the rack env.
have a look here:

from rack-tracker.

DonSchado avatar DonSchado commented on June 11, 2024

@petervandeput did that help? mind to share your solution for others?

from rack-tracker.

 avatar commented on June 11, 2024

Not really, problem I'm trying to solve is that when an amp version of the page is request (e.g. by Google) the code is not injected. still haven't figured out how to do

from rack-tracker.

DonSchado avatar DonSchado commented on June 11, 2024

I have no experience with AMP but let's figure this out.

Please refer to this spec as an example: f3d4e65#diff-f961e0b587e363c3a6cd9a6a3a231684

You have full access to anything in the rack env hash, which might look something similar to this:

{
  "GATEWAY_INTERFACE"=>"CGI/1.1",
  "HTTP_ACCEPT"=>"text/html,application/xhtml+xml",
  "HTTP_ACCEPT_ENCODING"=>"gzip",
  "HTTP_ACCEPT_LANGUAGE"=>"en-US,en;q=0.8,de;q=0.6",
  "HTTP_CACHE_CONTROL"=>"max-age=0",
  "HTTP_HOST"=>"localhost:3000",
  "HTTP_USER_AGENT"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X)",
  "HTTP_VERSION"=>"HTTP/1.1",
  "PATH_INFO"=>"/",
  "QUERY_STRING"=>"",
  "rack.version"=>[1, 3], 
  "rack.url_scheme"=>"http",
  "REMOTE_ADDR"=>"127.0.0.1",
  "REMOTE_HOST"=>"localhost",
  "REQUEST_METHOD"=>"GET",
  "REQUEST_PATH"=>"/"
  "REQUEST_URI"=>"http://localhost:3000/",
  "SCRIPT_NAME"=>"",
  "SERVER_NAME"=>"localhost",
  "SERVER_PORT"=>"3000",
  "SERVER_PROTOCOL"=>"HTTP/1.1",
  "SERVER_SOFTWARE"=>"WEBrick/1.3.1 (Ruby/2.2.1/2015-02-26)",
}

Are you sure the request url contains what you're looking for? or is it maybe the referrer?

So if the env hash is not enough, you should be able to access the controller instance with env["action_controller.instance"] and ask the request object for further information to decide if you inject the tracker.

from rack-tracker.

bumi avatar bumi commented on June 11, 2024

@petervandeput do you want to share an example on how you solved it?
This might be helpful for others who try to do similar things.

from rack-tracker.

Related Issues (20)

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.