Comments (7)
Hey @kohheepeace, thanks for following up with the solution 👍
from ahoy.js.
@kohheepeace you are a savior. Thanks.
from ahoy.js.
@kohheepeace followed the next.js config,
in utils/ahoy.js
// https://github.com/ankane/ahoy.js/issues/35
import Cookie from 'js-cookie'
const baseURL = process.env.RAILS_ENDPOINT;
const isServer = (typeof window === 'undefined')
let ahoy
if (!isServer) {
ahoy = require('ahoy.js').default;
ahoy.configure({
urlPrefix: '',
visitsUrl: `${baseURL}/ahoy/visits`,
eventsUrl: `${baseURL}/ahoy/events`,
page: "Bio page",
platform: 'Web',
useBeacon: true,
startOnReady: true,
trackVisits: true,
cookies: false,
cookieDomain: null,
headers: {'Authorization': `Bearer ${Cookie.get('accessToken')}`},
visitParams: {},
withCredentials: true
})
}
export default ahoy
but keep getting
Access to XMLHttpRequest at 'http://localhost:3000/ahoy/events' from origin 'http://localhost:5000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
in rails ahoy.rb
class Ahoy::Store < Ahoy::DatabaseStore
end
# set to true for JavaScript tracking
Ahoy.api = true
# set to true for geocoding
# we recommend configuring local geocoding first
# see https://github.com/ankane/ahoy#geocoding
Ahoy.geocode = true
Ahoy.job_queue = :low_priority
# since the request is from next JS server
# FIXME
Ahoy.track_bots = true
Please advise.
Thanks!
from ahoy.js.
@montekaka CORS error is very common issues. Using the rack-cors gem may solve the problem. And this is a tutorial https://admatbandara.medium.com/setting-up-cors-to-my-rails-api-a6184e461a0f to add this gem.
from ahoy.js.
@montekaka CORS error is very common issues. Using the rack-cors gem may solve the problem.
Thanks so much for the quick response. I setup it as well. I have cors.rb:
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*',
headers: :any,
expose: ['access-token', 'expiry', 'token-type', 'uid', 'client'],
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end
from ahoy.js.
I might have my issue solved by change the withCredentials to false.
from ahoy.js.
I actually had to add credentials: true
to the cors.rb initializer:
resource "*",
headers: :any,
methods: :any,
credentials: true
from ahoy.js.
Related Issues (20)
- ahoy.js does not track click events for a-tags that contain HTML tags. Is it intentional? HOT 3
- Click event is duplicated when redirect from A.html to B.html HOT 2
- Add the option to keep the ahoy_visit cookie alive HOT 2
- Why visitsUrl and eventsUrl should use double // on my side HOT 1
- Update the no-jquery branch HOT 1
- Support skipping certain tracked events inside a [data-no-track] tagged element HOT 10
- TypeError: Illegal invocation HOT 3
- Add debug messaging around sendbeacon HOT 1
- Cross-Origin Read Blocking (CORB) blocked cross-origin response HOT 1
- Why did you remove #trackAll ? (just curious) HOT 2
- [Idea] Remove TailwindCSS classes from "class" attribute in ahoy.js HOT 1
- Open to moving some helper functions to exports?
- [Idea] The ability to update a visit, or be able to start a visit programmatically.
- Next js and ahoy HOT 1
- Expo Support? HOT 2
- Using useBeacon: true results in NS_ERROR_FAILURES on events HOT 1
- [Idea] Extra attributes on clicks HOT 1
- [idea] trackSubmits could include the action url
- [help] NextJS + Ahoy
- Issue with SSR: window is not defined HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ahoy.js.