Giter VIP home page Giter VIP logo

getsetreff's Introduction

Store all referrers of website visitors

In April 2015, Google Analytics upgraded to a new tracking code and technology, named Universal Analytics. With the upgrade, the __utmz cookie that used to contain the last referrer details for each visitor was rolled out.

getSetReff() replicates the functionality of the __utmz cookie and adds a few features on top:

  • stores all the referrers of a visitor, not just the last referrer
  • is able to identify marketing campaigns as referrers, based on the utm parameters
  • stores the length of each visit both in time spent and in number of pages viewed

Setting it up now

Step 1: Set the domain on which the getSetReff script is added inside the dataLayer variable

<script type="text/javascript">
var dataLayer = dataLayer || [];
dataLayer.push({"getSetReff" : "v1.0", "setDomain" : ".ReplaceWithYourDomain.com"});
</script>

Step 2: Load the getSetReff.min.js under the dataLayer declaration. It can be done in an external file.

<script type="text/javascript" src="getSetReff.min.js"></script>

Step 3: Trigger the getSetReff() function.

<script type="text/javascript">
getSetReff();
</script>

Each time the function is triggered, it will write inside the following 2 cookies:

  • __reff stores all the details about all past referrers for at least 2 years
  • __sreff a session cookie used to calculate time spent on website and number of viewed pages. Gets deleted after the session expire

Step 4: Whenever you need, just store the content of the __reff cookie on your own database for future analyses.

Possible __reff values

Before diving into cookie examples, here is a bit of explanation of the special characters and elements found in the cookie:

  • | is used to mark out each visit with its traffic source
  • & is used to split the traffic source from the visit details
  • XXXXXXXXXXXX.XXXXXXXXXXXX.X.X represents _timestampVisitStart.timeStampLastAction.pagesViewed

Single referrer

When a visitor first gets to your website, the __reff will have a value similar to this one:

"[[landing-page]]hsrd.yahoo.com&1396714229529.1396714229529.1"

Multiple referrers

Subsequent future visits will drive the __reff cookie to grow to this

"[[landing-page]]hsrd.yahoo.com&1396714229529.1396714229529.1|[[landing-page]]www.google.com&1396714366071.1396714366071.1"

Marketing Campaigns as referrers

If the 3rd visit will be via a marketing campaign (which uses utm variables), the cookie will become

"[[landing-page]]hsrd.yahoo.com&1396714229529.1396714229529.1|[[landing-page]]www.google.com&1396714366071.1396714366071.1|[[landing-page]]c:[discount]m:[mail]s:[affiliate]&1396714474814.1396714474814.1"

c represents the campaign name, m the medium name and s the source name.

AdWords campaigns

If the 4th traffic source that brought the user to the website was AdWords, the cookie will look like this

"[[landing-page]]hsrd.yahoo.com&1396714229529.1396714229529.1|[[landing-page]]www.google.com&1396714366071.1396714366071.1|[[landing-page]]c:[discount]m:[mail]s:[affiliate]&1396714474814.1396714474814.1|[[landing-page]]cr:[XXXXXXXXXXXXX]m:[adwords]&1396714638762.1396714638762.1"

A typical scenarion for getSetReff()

Note: The code runs on each page visited by the visitor. It does not communicate with any external service or server. It simply stores a cookie in the browser of the user with the details of the traffic source that brought him to the website.

Each time a user visits your website the script will set the __reff cookie on his browser, with the details of his traffic sources.

Once the user converts (creates account, buys a product, sends a message) simply store the value in the __reff cookie in your database. Make sure to delete the __reff and __sreff cookies once you store them in order to avoid duplicate values in your database.

Optimized for Google Tag Manager

The getSetReff() script is optimized for Google Tag Manager. Just place the minified version of the code in either a dedicated Tag or any other tag that runs on all pages of your website.

The getSetReff() uses the standard dataLayer format that is already used by Google Tag Manager.

getsetreff's People

Contributors

innertrends avatar cllaudiu avatar

Stargazers

 avatar Nick Reese avatar Wayne Steidley avatar Nejc Rodošek avatar Ale avatar Gerardo Hernández avatar Michael Roper avatar Jordan Coeyman avatar Sam Taylor avatar martin g avatar  avatar Shoora avatar  avatar Daniel Puglisi avatar Kyle avatar Tom Wong avatar David Chun avatar Reza Qorbani avatar Franco Laiuppa avatar Boston Dell-Vandenberg avatar  avatar Sam Abouelata avatar  avatar  avatar  avatar Matthieu DANET avatar  avatar Paul Dariye avatar Marco Amato avatar John Balladares avatar  avatar  avatar Panagiotis Tzamtzis avatar Nevin Laughlin avatar Tony Dillon avatar Dave Romero avatar  avatar Samuel Lavoie avatar Ed Mazurek avatar Miguel avatar András Sevcsik-Zajácz avatar  avatar primoz klemensek avatar Bryan Selner avatar Julian Joseph avatar Joe St. Clair avatar Lauren Ancona avatar Luis Pérez avatar Joao Correia avatar Jiri Melcak avatar Hussain avatar Alex Stoia avatar

Watchers

Samuel Lavoie avatar Miguel avatar Tony Dillon avatar James Cloos avatar Alex Stoia avatar  avatar  avatar Ibrahim Kabadayi avatar  avatar  avatar Alex Vermeule avatar

getsetreff's Issues

GTM will not publish minified version

I get an error when I try to publish a custom HTML tag with the minifed script. GTM indicates the HTML is invalid. Can you please test and fix if needed?

Detailed ReadMe

Any chance there could be some more detail in the readme about setup in GTM with Datalayer for those who are less familiar with these tools. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.