2

Information:
I'm working on a phone-tracking project that uses the Google Analytics measurement protocol, that should do the following when finished:

  1. Add a event/hit to a goal in Google Analytics (predefined category/action)
  2. Add a conversion in Google Adwords

I'm Using the library:

Everything is setup according to php-ga-measurement-protocol, and it seems to be working - i can add event/hit to a goal in Google Analytics, without any problems.
But the problems comes when i'm asking Google Adwords to import the data(goals) from Google Analytics - it doesnt add any conversions - it says every hit just comes from "Direct/non".

Code:

$analytics = new TheIconic\Tracking\GoogleAnalytics\Analytics(true);
$analytics->setProtocolVersion('1')
          ->setHitType('event')
          ->setTrackingId($sGoogleAnalyticID)
          ->setClientId($sClientID)
          ->setEventCategory('MyEventCategory')
          ->setEventAction('MyAction')
          ->setEventValue(1)
          ->sendEvent();

I figured it made sense, since i'm not adding the UTM data, so i tried setting the UTM data on the $analytics object as seen below:

$analytics = new TheIconic\Tracking\GoogleAnalytics\Analytics(true);
$analytics->setProtocolVersion('1')
          ->setHitType('event')
          ->setTrackingId($sGoogleAnalyticID)
          ->setClientId($sClientID)
          ->setEventCategory('MyEventCategory')
          ->setEventAction('MyAction')
          ->setEventValue(1)
          ->setCampaignName($sUtmCampaign) //&utm_campaign=[xxxxx] - para name value is taken from
          ->setCampaignSource($sUtmSource) //&utm_source=[xxxxx] - para name value is taken from
          ->setCampaignMedium($sUtmMedium) //&utm_medium=[xxxxx] - para name value is taken from
          ->setCampaignContent($sUtmContent) //&utm_content=[xxxxx] - para name value is taken from
          ->sendEvent();

The Questsions:

  • am i missing some parameter's?
  • am i using the right values for the right parameter's?
  • am i using the right lib, or should i use something else?
  • should i even work with the goals in Google Analytics or should i use a Google Adwords API?
  • is their a easier way to do it?

I would appreciate any help or if someone could point me in the right direction - i have used countless hours googling and trying stuff.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Mac
  • 334
  • 1
  • 3
  • 13

2 Answers2

3

For the conversion hit to be assigned to a proper Google Ads campaign/keyword in a linked Google Analytics account it must belong to a session that starts with a pageview with a specified gclid=XXXXX parameter in the URL. The value of gclid is Google Ads click identifier and allows matching Analytics and Ads data. In case if your measurement protocol request is not aligned with the corresponding session the hit won't be recorded as a conversion in Google Ads. You might want to store the gclid serverside for each supposed conversion and include that in your measurement protocol location parameter. However, this might result in the creation of redundant sessions and unpredictable discrepancies in reporting.

Consult Analytics docs on campaign attribution for further details.

Arend
  • 3,741
  • 2
  • 27
  • 37
Дмитро Булах
  • 3,697
  • 1
  • 14
  • 23
  • Thank you for your quick response and taking time to help, i don't think your link is working correctly. I have been looking at the avalible parameters, and i cant seem to find any gclid parameter (see https://github.com/theiconic/php-ga-measurement-protocol/blob/master/src/Analytics.php) - is their no way i can just use the campaign UTM data? – Mac Jan 15 '20 at 14:36
  • gclid is not a measurement protocol parameter. It's an URL query parameter that is added to a landing page URL when a user clicks an ad on Google search page. So when the visitor gets to some page from ad this page URL looks like `example.com/page.php?gclid=123SDds234d3`. An exact URL is then passed to Google Analytics alongside other hit parameters and it fetches `gclid` from URL – Дмитро Булах Jan 15 '20 at 14:47
  • That makes sense, so i should pass the whole URL as DocumentLocationUrl? can i then ommit to pass; CampaignMedium, CampaignContent, CampaignSource and so on - since its all in the URL i'm passing – Mac Jan 16 '20 at 07:00
  • The only thing you can do is passing `gclid` parameter since it's the index key for matching Ads and Analytics data. – Дмитро Булах Jan 16 '20 at 07:30
  • i understand, i have the gclid (got it from testing an ad) - but im not sure what parameter i should pass it as - i have tried multiple diffrent things, and it never shows up in the "real time" conversion tab in google analytics, nor in google ads – Mac Jan 16 '20 at 08:57
  • try to pass this with a `dl` parameter (as for ` Document location`) – Дмитро Булах Jan 16 '20 at 16:15
2

TheIconic library you're using has a function for setting the "gclid" parameter of the measurement protocol event hit.. But first you have to extract the gclid from the _gac cookie..

$analytics->setGoogleAdwordsId($adwords_id);

You can find the "gclid" mentioned in Measurement Protocol parameter reference: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters

This talks about _gac and _glc cookies.. https://support.google.com/analytics/answer/7519794/use-google-analytics-to-support-google-ads-conversions?hl=en#zippy=%2Cin-this-article

The MG
  • 21
  • 1