visitData
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
to do it.
If you have any questions for this, drop me an email at ilkkapel@gmail.com
Here's the file you can include in your web page directly from CDN: https://cdn.jsdelivr.net/npm/visitdata/dist/visitdata.umd.js
npm install visitdata
clone this repository and then
npm install
npm run build
the javascript you need is at dist/visitdata.js
<script src="https://cdn.jsdelivr.net/npm/visitdata/dist/visitdata.umd.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