-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for custom dimensions and metrics #278
Comments
Hijacking the thread — I'm interested in passing some custom dimensions / metrics, but also passing other google analytics parameters (what they call "fields"). E.g. to force a session to start, you can pass an additional parameters object: // Starts a new session.
ga('send', 'pageview', {'sessionControl': 'start'}); I can't find any reference to this in the Google Analytics target docs, so I assume that neither custom dimensions/metrics nor session control is implemented, right? |
Right! @julienma @leandroz let's fix that! So, as a place to start, we do support custom dimensions on the React Native Google Analytics target. Here's the API we went with: https://rangle.gitbook.io/redux-beacon/index/react-native-google-analytics#screenview. We don't need to go with the same API for this target. We're using But, first, before we get into the implementation, let's land on a new API for import { trackPageView } from '@redux-beacon/google-analytics';
const pageView = trackPageView((action, prevState, nextState) => {
return {
page: /* fill me in */,
title: /* (optional) */,
location: /* (optional) */,
};
}, /* (optional) tracker name */ ); In an ideal world how would you like this to look, assuming support for custom dimensions and fields? |
Ha, excellent @ttmarek! I was just looking at the React Native target, as I saw it supports custom dimensions :) I'd mostly use this with import { trackEvent } from '@redux-beacon/google-analytics';
const myEvent = trackEvent((action, prevState, nextState) => {
return {
category: /* fill me in */,
action: /* fill me in */,
label: /* (optional) */,
value: /* (optional) */,
customFields: { /* (optional) */
[/* dimension index */]: /* dimension value */,
},
};
}, /* (optional) tracker name */ ); Note that I'm proposing to use a This make it more flexible, and answers both use case from this issue (custom dimensions / metrics + session control): // ...
customFields: {
'dimension5': 'custom dimension data', // custom dimension
'metric12': 'custom metric data', // custom metric
'sessionControl': 'start', // force start a session
'anonymizeIp': true,
// etc.
}, Actually, A couple of other things I'd like (I should probably create another issue?): 1. A way to set a
|
An additional fieldsObject makes sense for me, it's good to use the same terminology to avoid confusion. |
I love all of this.
import GoogleAnalytics from '@redux-beacon/google-analytics';
// Create or import an events map.
// See "getting started" pages for instructions.
const gaOptions = {
clientId?: string,
};
const ga = GoogleAnalytics(gaOptions);
const gaMiddleware = createMiddleware(eventsMap, ga);
const gaMetaReducer = createMetaReducer(eventsMap, ga);
|
|
This is great. I came just to write exactly the same feature request! |
@ttmarek I can't promise anything, but if I could set some time aside to help with this, where do you suggest I start? Copy/pasting the things related to custom dimensions from the React Native target? |
@leandroz @julienma @xpander001 Sorry for the delay on this, I've had some projects at home that have been keeping me busy on my evenings/weekends. I have a pull request that add's support for custom dimensions via the fieldsObject here: #287 I was hoping one or more of you could help me out by trying out the new changes and seeing if it works and meets your needs. You can install the changes under the
|
Thanks @ttmarek. |
@ttmarek What are your preferences on submitting contributions here? I need to use the session start stop feature described here (https://github.com/idehub/react-native-google-analytics-bridge#hitpayload) on the react-native-google-analytics-bridge and am happy to add it in a PR, but don't know how you to want to handle the parameter differences that'll need to happen in the event-helpers and google-analytics files. |
Hey @kevinsperrine.
No real preferences. Just come up with your dream API for the new additions and we can chat about them. Ideally the API would more or less align with the existing patterns we have so we don't have to disrupt too many users. |
Sorry if I'm out of the loop, but this merged PR which is linked to in the docs seems to say you can can add custom variables by setting a particular hit type, and adding by adds the customDimensionDict key: const pageView = action => ({
hitType: 'pageviewCustomDimensions',
page: action.payload,
customDimensionDict: {
'1': 'premium',
'5': 'foo'
}
}) However, I have tried this and it does not seem to work. |
This is a...
Which target(s) are you using?
🚀 📜 What's missing from Redux Beacon that you'd like to add?
Custom dimensions and metrics are a powerful way to send custom data to Google Analytics. Web developers can use custom dimensions and metrics to segment and measure differences between logged in and logged out users, authors of pages, levels in games, or any other business data you have on a page.
https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets
So basic idea is to add support for this, the problem I see is that we don't know in advance the field key, as it would be anything between dimension1 and dimension20, and the same for metrics. (The number of custom dimensions and metrics varies between plans I believe)
One option would be to pass a dimensions object with numbers as keys, and then build the parameters from there. I will be happy to send a PR once agreed on the design.
Examples:
Can you help out?
The text was updated successfully, but these errors were encountered: