GithubHelp home page GithubHelp logo

miguelramosfdz / getsetreff Goto Github PK

View Code? Open in Web Editor NEW

This project forked from innertrends/getsetreff

0.0 2.0 0.0 170 KB

getSetReff

License: GNU General Public License v3.0

JavaScript 100.00%

getsetreff's Introduction

Store all referrers of website visitors

In April 2014, 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

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:

"hsrd.yahoo.com&1396714229529.1396714229529.1"

Multiple referrers

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

"hsrd.yahoo.com&1396714229529.1396714229529.1|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

"hsrd.yahoo.com&1396714229529.1396714229529.1|www.google.com&1396714366071.1396714366071.1|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

"hsrd.yahoo.com&1396714229529.1396714229529.1|www.google.com&1396714366071.1396714366071.1|c:[discount]m:[mail]s:[affiliate]&1396714474814.1396714474814.1|www.google.com:[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

cllaudiu avatar innertrends avatar

Watchers

 avatar  avatar

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.