Search code examples
google-analyticsgoogle-analytics-apiwebhooksuniversal-analytics

Using webhooks with Google Analytics


I'm trying to integrate my CRM with Google Analytics to monitor lead changes (from lead to sell) and so on. As I understood, I need to use Google Measurement Protocol, to receive webhooks from CRM and translate it to Analytics Conversions.

But in fact, I don't really understand how to do it. I need to make some script, to translate webhook code to analytics, but where I need to place that script? Are there some templates? And so on.

So, If you know some tutorials/courses/freelancers to help me with intergrating webhooks with Analytics - I need your advice.

Example of webhook from CRM:

{
    "leads": {
        "status": {
            "id": "25399013",
            "name": "Lead title",
            "old_status_id": "7039101",
            "status_id": "142",
            "price": "0",
            "responsible_user_id": "102525",
            "last_modified": "1413554372",
            "modified_user_id": "102525",
            "created_user_id": "102525",
            "date_create": "1413554349",
            "account_id": "7039099",
            "custom_fields": [
                {
                    "id": "427183",
                    "name": "Checkbox custom field",
                    "values": ["1"]
                },
                {
                    "id": "427271",
                    "name": "Date custom field",
                    "values": ["1412380800"]
                },
                {
                    "id": "1069602",
                    "name": "Checkbox custom field",
                    "values": ["0"]
                },
                {
                    "id": "427661",
                    "name": "Text custom field",
                    "values": ["Валера"]
                },
                {
                    "id": "1075272",
                    "name": "Date custom field",
                    "values": ["1413331200"]
                }
            ]
        }
    }
}

Solution

  • I've done just this in my line of work.

    You need to first decide your data model on how you would like the CRM data to look within Google Analytics. This could be just mapping Google Analytics' event category, event label, event action to your data, or perhpas using custom dimensions and metrics.

    Then to make it most useful, you would like to be able to link the CRM activity of a customer to their online activity. You can do this if they login online. In that case, you can set the cid and/or uid of the user to your CRM id.

    Then, if you send in a GA hit with the same cid/uid in your Measurement Protocol hit, you will link the online sessions with your offline CRM activity.

    To make the actual record hit Google Analytics, you will need to program something that takes the CRM data and turns it into a Measurement Protocol hit, which is essentially just a URL with the correct parameters. Look here for reference: https://developers.google.com/analytics/devguides/collection/protocol/v1/reference

    An example could be: http://www.google-analytics.com/collect?v=1&tid=UA-123456-1&cid=5555&t=pageview&dp=%2FpageA

    We usually have this as a seperate process, that fires when the CRM data is written to its database (the webhook in your example). If its a lot of data, you should probably implement checks to see if the hit was sucessful, and caching in case the service is not online - you have an optional parameter that gives you 4 hours leeway in sending data.

    Hope this gets you at least started.