Comments (2)
Thanks for pointing this out. The track_forms()
helper is a little bit too simple for your scenario: since it only overrides the form submission event rather than clicks on individual form elements, there's no way to re-submit the form programmatically along with a particular submit input's value (see http://stackoverflow.com/questions/1709301/javascript-submit-does-not-include-submit-button-value for some explanations).
There's a fairly lightweight workaround: use a hidden form field to tell your server which button was pressed, and set its value in a click-handler on your submit buttons. Here's an implementation with ugly inline+global JS (if you use jQuery or other libs, this can be cleaner and unobtrusive):
<input id="submit_type" name="submit_type" type="hidden" value="paid">
<input name="free_sub" value="Free" type="submit" onclick="setSubmitType('free')">
<input name="paid_sub" value="Paid" type="submit" onclick="setSubmitType('paid')">
<script>
function setSubmitType(stype) {
document.getElementById('submit_type').value = stype;
}
</script>
then your server-side check can be something like:
patch :confirm, constraints: lambda {|req| req.params[:submit_type] == 'free'}, action: :free_subscribe
patch :confirm
How do you feel about that approach? In general, particular values from submit
inputs are difficult to work with in JS, so people often avoid them for anything except the most straightforward HTML form scenarios.
from mixpanel-js.
This is also happening to my team. The workaround proposed by @tdumitrescu sadly can't easily work for us, because our code doesn't generate the form, it's generated by an upstream dependency that we are not allowed to patch... as a possible idea for a fix, could Mixpanel save the information about the pressed submit button, and repackage it, maybe as a hidden input to be sent in the POST request?
from mixpanel-js.
Related Issues (20)
- The latest version of the library is different between NPM and CDN HOT 2
- unintended behavior with marketing campaign tracking in the minified version HOT 2
- Long urls are cut off
- Endpoint with track/? is not a valid URL with recent jars of spring boot 3, is there any chance to remove / after track in mixpanel.cjs.js HOT 1
- Allow async init HOT 6
- Can `api_host` contain a /path? HOT 4
- Cannot read properties of undefined (reading 'persistence')
- Reset not available on mixpanel instance
- Target attribute other than _blank is ignored. HOT 1
- Cannot add event properties to Page View event when track_pageview: true in SPA HOT 1
- Reset Mixpanel before init
- mixpanel.track_pageview does not send any event
- `track_links` does not work in a React app unless wrapped in a `useEffect` + `setTimeout`
- `$initial_referrer` property shows up as `"$direct"`, even when it isn't HOT 8
- Pass custom `device_id` to library initialization HOT 5
- mixpanel.identify() works even when it is turned off. HOT 1
- .github/workflows/tests.yml `uses node12 which is deprecated`
- is it possible to flush all batched events at once? HOT 1
- Passing property "time" doesn't show events in the mixpanel UI
- Remote code inclusion (mixpanel-recorder.min.js) HOT 2
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 mixpanel-js.