The problem
At YPlan, we found that using Segment on a Single Page Application is causing Google Analytics to break the sessions, giving us the wrong PPC vs Organic attributions.
The cause is that Segment is always sending the original referrer with the current (updated) url.
How to reproduce it
We created a simple SPA with React and React Router to reproduce the problem.
Landing on the application and clicking the links (i.e. updating the url) from a different referrer (e.g. jsfiddle) with the utm parameters results in a split session:
This is the "raw" Google Analytics data sent via Segment:
v:1
_v:j40
a:120322824
t:pageview
_s:1
dl:http://localhost:8000/?utm_source=michele&utm_medium=spa/
dr:http://fiddle.jshell.net/_display/
dp:/?utm_source=michele&utm_medium=spa/
ul:en-us
de:windows-1252
dt:Segment SPA
sd:24-bit
sr:1680x1050
vp:1123x332
je:1
fl:19.0 r0
_u:SCCAgAAj~
jid:
cid:1913804964.1439278034
tid:UA-32643507-4
v:1
_v:j40
a:120322824
t:pageview
_s:2
dl:http://localhost:8000/two
dr:http://fiddle.jshell.net/_display/
dp:/two
ul:en-us
de:windows-1252
dt:Segment SPA
sd:24-bit
sr:1680x1050
vp:1123x332
je:1
fl:19.0 r0
_u:SCCAgAAj~
jid:
cid:1913804964.1439278034
tid:UA-32643507-4
z:1688857593
v:1
_v:j40
a:120322824
t:pageview
_s:3
dl:http://localhost:8000/three
dr:http://fiddle.jshell.net/_display/
dp:/three
ul:en-us
de:windows-1252
dt:Segment SPA
sd:24-bit
sr:1680x1050
vp:1123x332
je:1
fl:19.0 r0
_u:SCCAgAAj~
jid:
cid:1913804964.1439278034
tid:UA-32643507-4
z:1714268981
Overriding the referrer
We read the documentation and we tried to override the referrer, as follows:
history.listen(() => {
analytics.page('category', 'name', {
referrer: 'https://www.itsarainysunnyday.com'
});
});
But we found that Segment keeps on sending the original referrer to Google Analytics:
v:1
_v:j40d
a:2007255171
t:pageview
_s:1
dl:http://localhost:8080/
dr:http://fiddle.jshell.net/_display/
dp:/
ul:en-us
de:windows-1252
dt:category name
sd:24-bit
sr:1680x1050
vp:1676x216
je:1
fl:19.0 r0
_u:SCCAgAAj~
jid:
cid:2131063951.1440664624
tid:UA-32643507-4
z:1217894582
While it's sending the right one in the context
:
path: "/"
referrer: "https://www.itsarainysunnyday.com"
search: ""
title: "Segment SPA"
url: "http://localhost:8080/"
Any suggestions?