Sometimes I have two share buttons in my application UI (depending on state). They can share the same data, but are located in different parts of the UI. We want to analyze from which button (part of UI) the share was executed. I was hoping to use the fieldsObject
field for this part, as shown in the documentation:
ga('send', 'social', [socialNetwork], [socialAction], [socialTarget], [fieldsObject]);
However, all the examples I can find only utilize the three first fields, typically something like:
ga('send', {
hitType: 'social',
socialNetwork: 'Twitter',
socialAction: 'share',
socialTarget: 'http://www.example.com/article-01'
});
Also, I don't understand what the documentation means by:
"Note that as with all send commands, the fields passed in the convenience parameters may also be specified in the
fieldsObject
."
I thouhght maybe I was utilizing the "convenience parameter". My sharing code (from an Angular service):
reportShare(media:string, context: string) {
let pageUrl: string = this.sanitizeURL();
ga('send', {
hitType: 'social',
socialNetwork: media,
socialAction: 'share',
socialTarget: pageUrl,
fieldsObject: context
});
}
My Google Analytics Debugger says:
VM5405 analytics_debug.js:16 Running command: ga("send", {hitType: "social", socialNetwork: "Twitter", socialAction: "share", socialTarget: "/find/1160", fieldsObject: "machine"})
But then:
Set called on unknown field: "fieldsObject".
And as we can see from the the rest, "fieldsObject" is not passed along:
adSenseId (&a) 1505578412
anonymizeIp (&aip) 1
apiVersion (&v) 1
clientId (&cid) 1703756191.1573561297
encoding (&de) UTF-8
hitType (&t) social
javaEnabled (&je) 0
language (&ul) en-us
location (&dl) http://localhost/find/1160
screenColors (&sd) 24-bit
screenResolution (&sr) 1680x1050
socialAction (&sa) share
socialNetwork (&sn) Twitter
socialTarget (&st) /find/1160
title (&dt) This pagetitle
trackingId (&tid) UA-*********-1
viewportSize (&vp) 1680x916
Is there a way to pass along the fieldsObject with my context string using social interaction?
Thank you for replying! Firstly, I've moved from analytics.js to gtag.js.
I created Custom Dimensions in the GA interface: Admin > Custom Definitions > Custom Dimensions, and gave it the name "Share Context". Custom Dimensions for gtag is documentet here.
I then update my js calls:
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-**********-*', {
'custom_map': {'dimension1': 'context'},
'custom_map': {'dimension2': 'context'},
'anonymize_ip': true,
'allow_ad_personalization_signals': false
});
In my reporting service I then can call:
reportShare(media:string, context: string) {
gtag('event', 'Sharing Context', {
'dimension2': context,
'event_category': 'social',
'event_label': media,
'value': this.sanitizedURL
});
}
Finally, under Acquisition > Social > Plugins I can access my custom dimension from Social Entity > Secondary Dimensions > Custom Dimension > Share Context (which is the name you provide when creating the custom dimension).
More about reporting non-standard data as custom dimensions & metrics.