introduction to google analytics for developers

29
Introduction to Google Analytics for developers Ruben Martinez

Upload: ruben-martinez

Post on 20-Jun-2015

670 views

Category:

Data & Analytics


4 download

DESCRIPTION

Description of the Google Analytics platform, how the tracking code works, metrics and dimensions, event hits, tests A/B, clientID and user_id

TRANSCRIPT

Page 1: Introduction to Google Analytics for developers

Introduction to Google Analytics for developers

Ruben Martinez

Page 2: Introduction to Google Analytics for developers

You have visitors.

Source: http://www.seriaticos.com.br/2011/01/game-of-thrones-nova-serie-da-hbo.html

Page 3: Introduction to Google Analytics for developers

This graph compares the count of visitors from Google organic search to a website in two periods of time.

The story it is telling us is good news: the organic traffic markedly increased in a given month over the same periodof the previous year (due to a previous investment in content and SEO).

Google Analytics reports incoming traffic to webs and apps

Introduction to Google Analytics - @RubenMartinezS

Page 4: Introduction to Google Analytics for developers

Google Analytics helps understand your visitors’ flows

Introduction to Google Analytics - @RubenMartinezS

Traffic volume by channel e.g. sessions per campaign and geolocation

Engagement• Depth• Density• Duplication

Content• A/B testing• Path Analysis

Page 5: Introduction to Google Analytics for developers

• A platform to track online and off-line activity of aggregated and anonymized visitors’ data

• A behavioural reporting platform of activity of web visitors and end-users

• A bread-and-butter tool for webmasters and marketing and business analysts

• A (peculiar) dashboard interface and a well documented API

Google Analytics is:

Introduction to Google Analytics - @RubenMartinezS

Page 6: Introduction to Google Analytics for developers

The war of Web Analytics platforms: GA and SiteCatalyst

Introduction to Google Analytics - @RubenMartinezS

Number of websites using Google Universal Analytics (left) vs. Omniture SiteCatalyst (below).

Graphs with the same vertical scale and similar periods of time.

Source: builtwith.com

Page 7: Introduction to Google Analytics for developers

Developers can access Google Analytics via a front interface, client libraries and APIs. This is how each components and APIs are organized:

Organization of the platform

Source: https://developers.google.com/analytics/devguides/platform/

Introduction to Google Analytics - @RubenMartinezS

Page 8: Introduction to Google Analytics for developers

• A transactional CRM tool

Visitors’ individual data is owned by Google Inc. The end userhas access to anonymized data only.

• A reporting tool of websites only

It can be configured to track offline and online activity frommultiple devices, including smartphones, kiosks, consoles, etc.

• A parser of web server logs

• A KPI-centric Business Intelligence platform

Google Analytics is NOT:

Introduction to Google Analytics - @RubenMartinezS

Page 9: Introduction to Google Analytics for developers

We need your undivided attention for the next 5 slides.

Source: http://www.secretsinplainsight.com/2014/page/4/

Page 10: Introduction to Google Analytics for developers

Tracking code

Introduction to Google Analytics - @RubenMartinezS

<script>

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)

})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-2282690-1', 'paradigmatecnologico.com');

ga('send', 'pageview');

</script>

When the browser loads this script, it interprets the document.write and triggers a sequence of events leading to send hits to Google’s server.

Sign up to Google Analytics. If are tracking a website on the admin panel, setup a property (URL). Then paste the code provided by Google (example below) on all the pages you want to track:

Page 11: Introduction to Google Analytics for developers

Browsers sends hits to Google Analytics server

Introduction to Google Analytics - @RubenMartinezS

Sequence of events:

1. The client brower requests the javascript file2. The Google Analytics server responds with the analytics.js file3. The client fetches, loads and executes the javascript which dynamically creates an <img> element in the DOM4. A GET from the browser hits the GA’s server with a URL containing appended values of the browser and the computer. 5. The server reads the data in the image URL and stores the hit (e.g. pageview or event) for logging and processing6. 6. The server responds with a single-pixel gif

http://www.google-

analytics.com/collect?v=1&_v=j20&a=806449001&t=pageview&_s=1&dl=http%3A%2F%2Fwww.paradigmatecnologico.co

m%2F&ul=en-us&de=UTF-8&sd=24-

bit&sr=1920x1080&vp=1920x199&je=1&fl=13.0%20r0&_u=MAC~&cid=416165610.1399537988&tid=UA-2282690-

1&z=2140666386

Page 12: Introduction to Google Analytics for developers

The 3 most important variables: t, cid and tid

Introduction to Google Analytics - @RubenMartinezS

o t=pageview // Pageview hit type

o cid=416165610.1399537988 // Anonymous ClientID

o tid=UA-2282690-1 // Tracking Web property ID

Page 13: Introduction to Google Analytics for developers

Visualization of tags and scripts

Introduction to Google Analytics - @RubenMartinezS

The analytics.js JavaScript library uses a single cookie.

The cookie contains an anonymous identifier used to distinguish users.

Page 14: Introduction to Google Analytics for developers

analytics.js Google Analytics cookies

Introduction to Google Analytics - @RubenMartinezS

By default, the analytics.js library sets cookies on thetop level domain, excluding the leading dot, and setsthe cookie path to the root level (/).

The name of the cookies is _ga

Note: The analytics.js library does not require settingcookies to transmit data to Google Analytics.

Page 15: Introduction to Google Analytics for developers

What youCAN dowithGoogle Analytics

Source: http://finance.yahoo.com/news/10-weird-things-people-done-200200984.html

Page 16: Introduction to Google Analytics for developers

• Track activity BEFORE pushing a brand new website or mobile app public

• Report activity on private areas (protected by a login and/or disallowed to crawling bots)

• Link to Adwords (CPC), GDN (CPM) and FDA (retargeting)

• Associate engagement data from different devices and multiple sessions (great for attribution)

• Upload transactional data of own userIDs if anonymized (great for e-commerce)

• Integrate your Google Analytics data with other business applications, e.g. via API

• Report activity across domains (tagging is however tedious and impractical)

What you CAN do with Google Analytics

Introduction to Google Analytics - @RubenMartinezS

Page 17: Introduction to Google Analytics for developers

• Generate leads (post-click marketing). Google Analytics does not provide IP addresses or the name of the company visiting a website for instance – and you should not upload this information either

• Upload personally identifiable information (see userIDs above)

• Carry out experiments across multiple domains (cross domain reporting OK but not tests A/B)

• Report –efficiently- inventory on e-commerce websites with SKUs

What you CANNOT do with Google Analyics

Introduction to Google Analytics - @RubenMartinezS

Page 18: Introduction to Google Analytics for developers

Metrics & dimensions

Source: http://ohnotheydidnt.livejournal.com/81841969.html

Page 19: Introduction to Google Analytics for developers

Metrics and dimensions

Dimensions are attributes of • Visitors• Sessions• Hits: page, event

The values of dimensions are strings.

Metrics are counts (average integer or currencies). Values of metricsare numbers.

Each custom dimension and metrics has an associated index.

There is a maximum of 20 custom metrics and dimensions

Introduction to Google Analytics - @RubenMartinezS

Page 20: Introduction to Google Analytics for developers

Event hits

Some user actions do not generate pageviews.

- completion of individual form fields (“Send”)- external, mailto: and pdf links- video play or complete- AJAX, Flash, jQuery or HTML5 interactions

You want to tag some HTML elements as events. Event tracking turns a normal

<a href=“/documents/e-book.pdf”>

into

<a href=“/documents/e-book.pdf”

onclick=”ga(‘send’,’event’,’link’,’pdf’)”>

Introduction to Google Analytics - @RubenMartinezS

Page 21: Introduction to Google Analytics for developers

Metrics and dimensions

ga('send', 'pageview', { 'dimension5': '<?=$author?>' });

For example, if your page is scripted in PHP, the actual author of the page will probably be stored in a PHP variable like $author.

In your PHP template, you can use this author variable to pass the author value to the custom dimension

Page 22: Introduction to Google Analytics for developers

Tests A/Bakaexperiments of behaviour

Source: http://arresteddevelopment.wikia.com/wiki/Tobias_F%C3%BCnke

Page 23: Introduction to Google Analytics for developers

Introduction to Google Analytics - @RubenMartinezS

Content Experiments based on a multi-armed bandit approach

Page 24: Introduction to Google Analytics for developers

How Much Does Google Really Know About You?

Source: http://blogs.mprnews.org/statewide/2014/04/hoot-or-insult-fargo-television-series-debuts-on-fx/

Page 25: Introduction to Google Analytics for developers

Google Analytics Universal is user-centric

Introduction to Google Analytics - @RubenMartinezS

Cookies reside in desktop browsers. Advertisers cannot track individual users due to the proliferationof smartphones. Cookies are not used by mobile apps and browsers such as Safari on iphones.

The identification of users and their sessions takes place now at server level on Universal, notbrowser/cookie level.

Cookies are still used but Google warns that their format might change without warning. Hencedevelopers should not directly access the cookie analytics.js sets as it could lead to script errors andincorrect data.

Instead, developers should use the get command to retrieve the clientId value when needed. Here's how to do this:

ga(function(tracker) { var clientId = tracker.get('clientId'); });

Page 26: Introduction to Google Analytics for developers

clientId for cross-device attribution

Introduction to Google Analytics - @RubenMartinezS

You can use a custom visitor ID based on customer email or ID in your database to merge smartphone /laptop / pc sessions into one cross-device session. You can track users who login to your website(authenticated users) by associating their clientID to their email.

<?if ($isAuthenticatedUser):?>

ga('create', 'UA-XXXX-Y', {'clientId': '<?=md5($email)?>' });

<?else:?>

ga('create', 'UA-XXXX-Y');

<?endif;?>

All users who sign in to your website will be tracked across all devices.

GA uses cookie value + domain as a unique internal identifier. If two or more websites set up the sameclient ID value based on customer email, the data won't be corrupted, because they are using differentdomains (and different GA profile id).

Page 27: Introduction to Google Analytics for developers

Link your acquisitions, engagement, and conversions

Introduction to Google Analytics - @RubenMartinezS

In a typical e-commerce scenario, you generate unique User_IDs through the authentication passed to an account at sign-in. The User ID will allow you to track for instance transactions and activity on per customer basis.

To enable this feature, add the following line to your tracking code to send User-ID data to Google Analytics.

ga('create', 'UA-XXXX-Y', { 'userId': 'USER_ID' });

ga('send', 'pageview');

where USER_ID is a string and represents the stable and unique ID retrieved from your system.

You can then send anonymized data based on User_IDs to Google Analytics.

Page 28: Introduction to Google Analytics for developers

That’s just taste of it

Source: http://us.cdn281.fansshare.com/photos/alexanderskarsg%C3%A5rd/alexander-skarsgard-eric-true-blood-photos-true-blood-681587477.jpg

Page 29: Introduction to Google Analytics for developers

Thank you!

If you enjoyed these slides or have suggestions to improve them, let us know!

@rubenmartinezs