https://github.com/pearmill/attribution.js
Attribution.js – a localized tracking script to attribute marketing channels
https://github.com/pearmill/attribution.js
analytics attribution markeitng
Last synced: about 2 months ago
JSON representation
Attribution.js – a localized tracking script to attribute marketing channels
- Host: GitHub
- URL: https://github.com/pearmill/attribution.js
- Owner: pearmill
- License: mit
- Created: 2019-12-20T12:07:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T04:27:43.000Z (over 3 years ago)
- Last Synced: 2025-11-15T15:23:51.356Z (7 months ago)
- Topics: analytics, attribution, markeitng
- Language: JavaScript
- Homepage:
- Size: 735 KB
- Stars: 10
- Watchers: 1
- Forks: 4
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Attribution.js
Attribution.js automatically collects and stores marketing channel data into localStorage, and makes it available via a simple to use API to be used in internal and external analytics tools.
Attribution.js is open source and powers our attribution and lead scoring tools at [Pearmill](https://pearmill.com?utm_campaign=attribution-js&utm_source=open-source&utm_medium=github), a software-powered advertising growth studio.
You can read [this short background story](https://github.com/pearmill/attribution.js/#background) about why we've developed this and what problem it solves.
Specifically, this library, tracks all UTM parameters (`utm_campaign`, `utm_source`, etc.) as well as a few key cookies (`_fbp`, `_fbc` from Facebook, `_ga` from GA, etc.) and saves them to localStorage. You can then retrieve them and pass them along as part of user actions to your internal or external analytics tools.
## Getting started
The easiest way to get started is to embed the script onto every page of your website, and retrieve the data when the user is making an action to retrieve the latest attribution data.
### Install
If you have a single-page web-app, you can use the package:
```bash
npm install @pearmill/attribution.js
# Or if you're using Yarn
yarn add @pearmill/attribution.js
```
## Embed
Alternatively, you can embed the script by copy pasting the code below:
```javascript
!function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(t,e,r){var n,o;!function(i){if(void 0===(o="function"==typeof(n=i)?n.call(e,r,e,t):n)||(t.exports=o),!0,t.exports=i(),!!0){var c=window.Cookies,u=window.Cookies=i();u.noConflict=function(){return window.Cookies=c,u}}}((function(){function t(){for(var t=0,e={};t=0&&(r[a]=f)})),r),cookies:u(m),page:window.location.href},m.trackReferrer&&(g.referrer=document.referrer),m.ignoreVisitsWithoutUTMParameters){var i=!0;if(Object.keys(g.query||{}).forEach((function(t){/utm/i.test(t)&&(i=!1)})),i)return void a("Ignoring visit, no UTM parameters found.")}if(!m.visitFilterFunction||m.visitFilterFunction(g)){var c=[].concat(d(n),[g]).filter((function(t){return!!t}));return c.length>m.limitVisits&&(c=[c[0]].concat(d(c.splice(2,c.length)))),function(t,e){try{var r=JSON.stringify(e);localStorage.setItem(t.localStorageName,r)}catch(t){f("[localStorage.setItem + parse failed]",t)}}(m,c),g}a("Ignoring visit, visitFilterFunction returned falsey.")},b=function(t){return t&&(m=function(t){for(var e=1;e