Salesforce Google Analytics Integration



A Little Background About This Post:

In my recent project with one of my client , they came up with salesforce to Google Analytics integration as their challenge as  they were interested to see all page stats in salesforce itself .
I worked over this piece of integration and thought of sharing this with community .

Here we go for step by step guide .

Part 1: Create an oAuth ID (Other)
  1. Go to: https://console.developers.google.com
  2. Create a new project
  3. Enable the “Analytics API”New project creation
Go to credentials
  1. Create “oAuth Client ID”
  2. Configure (Other) and save
  3. Give it a name
  4. Save the client ID and client secret
  5. Download the JSON






Part 2: Compile the following URI call from the JSON 

https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/analytics&redirect_uri=YOUR_REDIRECT_URI_HERE&response_type=code&client_id=YOUR_CLIENT_ID_HERE
·         YOUR_REDIRECT_URI_HERE: Site which need to be tracked.
Call the above URI.

Part 3: If done right… you will get this screen. Answer ALLOW! 

Google will then issue you with this token – it may only be used once.






Get Access Token

With the following parameters:
HEADER:
  • Content-Type: application/x-www-form-urlencoded
BODY:
  • grant_type: authorization_code
  • code:<CODE> (Code generated in previous step)
  • client_id: YOUR CLIENT ID from setup
  • client_secret: YOUR CLIENT SECRET from setup
  • redirect_uri: <URL to track>
Response
{
    "access_token": "<Access Token>",
    "expires_in": 3600,
    "token_type": "Bearer"
}



After login get url similar to below
where IDs is in the red after letter ‘p’. Which is used in next step
JS Code from tracking Info section need to be pasted in website which need to be tracked.
Sample
<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','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-101670932-1', 'auto');
  ga('send', 'pageview');

</script>

Part 6: Use the access_token to access any Google Analytics API URI





Comments

  1. The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface.

    jogos friv gratis 2019
    Jogos 2019
    jogos friv

    ReplyDelete

Post a Comment

Popular posts from this blog

A Quick Salesforce OAuth 2.0 Usage Demonstration

Salesforce To Authorize.Net Integration

Salesforce Shopify Integration