visitdata.js emulates the source, medium, campaign, content and term data just like Google Analytics does it (ga.js).
Since there is no way to extract this information from ga.js directly, you need a library like visitdata.js to do it.
Here's the file you can include in your web page directly from CDN: https://cdn.visitdatajs.com/latest/visitdata.js
If you have any questions for this, drop me an email at [email protected]
clone this repository and then
npm install
npm run build
the javascript you need is at dist/visitdata.js
I'm loading this from a CDN, but you might want to host the file yourself.
<script src="https://cdn.visitdatajs.com/latest/visitdata.js"></script>
<script>console.log(visitData.get());</script>
visitdata.get()
will return an object like
{
"source": "google",
"medium": "organic"
}
You can also run visitdata.rawData()
which will return a lot more information
Typically you likely need this data elsewhere. If so, combine this with globalStorage