mixpanel


Mixpanel cookie not being set


TL;DR; Mixpanel doesn't set its cookie provoking the distinct_id to change constantly
I have 3 mixpanel projects: local/staging/pro. In local mixpanel tracking is working just fine, but in staging even with the code being identical (except the mixpanel token), events are being sent properly, but always with a disting_id changed. So, I see every event in mixpanel as if it were coming from a different device?!
I checked it and the problem is probably coming from the fact that mixpanel is not setting its cookie at all in my browsers.
The source code for staging looks like this:
<head>
...
<script type="text/javascript" async="" src="//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js"></script>
before
<script>
(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d])};b.__SV=1.2;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f)}})(document,window.mixpanel||[]);
mixpanel.init("xxxxxx3ecxxx68a2ff74xxxx", {debug:true});
</script>
and finally I track
<script>
mixpanel.track('Visit');
</script>
If it is your staging site, you might be using a top level domain that don't allow cross subdomain cookies (think heroku, aws, etc), for example, yoursubdomain.herokuapp.com. You can either:
Map your staging yousubdomain.topleveldomain.com to staging.yourdomain.com using a CNAME record in your DNS settings
or
Manually enable cookies in mixpanel.init
mixpanel.init(PROJECT_TOKEN, {cross_subdomain_cookie : false});
Here is the mixpanel doc that explains: https://mixpanel.com/help/questions/articles/mixpanel-and-herokuappcom-subdomains-and-other-common-top-level-domains
And here is the list of top level urls that breaks cookies: https://publicsuffix.org/list/effective_tld_names.dat

Related Links

how to see value of distinct_id in Mixpanel
Is there a wildcard character for the Mixpanel API “export” method “event” parameter?
how to do mixpanel.people.increment in Segment
how to get total number of mixpanel events via API
creating a profile with mixpanel to track users not working
How to deal with users who signed up before Mixpanel alias was set up?
Mixpanel — delete user with all past data
Google Mobile Analytics Event Tracking: Multiple properties to describe an event in google analytics
Mixpanel how to check if user exist?
Can I use data attributes as a selectors for Mixpanel mixpanel.track_links?
Where do I set user profile in my code for registered users and the users who are going to register in future using Mixpanel?
What does Mixpanel's $signup event do?
Mixpanel: distinct_id being set but events not recording against profile
How to export Mixpanel events, segmented by time?
Waiting for mixpanel JS lib to be ready so I can get users distinct_id
What should I do when users log out?

Categories

HOME
xcode
typelite
adfs3.0
plaid
odata
dji-sdk
jint
pyresttest
migrate
orc
pm2
fosuserbundle
maven-plugin
checkout
jest
data-type-conversion
batch-rename
intel
backendless
react-dnd
data-collection
high-availability
marquee
docx4j
locks
premake
series
xcrun
mongoengine
char-pointer
rails-postgresql
busboy
landscape
ng-repeat
recovery
cheat-engine
extbase
angular-datatables
hypothesis-test
optionaldataexception
dbcc
common-table-expression
openstack-glance
renderman
gnome-terminal
clrs
http4s
d3v4
researchkit
svnserve
declarative
node.js-connect
strpos
certificate-authority
voronoi
cortana
in-app-billing
decidable
largenumber
openshift-cartridge
highest
360-degrees
algebraixlib
alwayson
abstract-factory
dbmigrate
shoes
jcheckbox
zend-mail
window-resize
.htpasswd
bittorrent-sync
preorder
particle-swarm
sensormanager
dynamic-rdlc-generation
days
smartfox
system-requirements
viewpagerindicator
prototypal-inheritance
acpi
differentiation
fork-join
nsconnection
django-pagination
eaccelerator
chunking
outlook-2007-addin
android-input-method
eventaggregator
rational-unified-process
projectpier
isapi-redirect

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App