Comments (6)
Sounds good @shayc!
Let me know if you have any questions.
from redux-beacon.
Thanks for reporting the issue @shayc 🎉
🙌
from redux-beacon.
Any news on this? Thanks
from redux-beacon.
@mihaiblaga89 I've been having some packed days lately (moving an apartment), hadn't had much time to work on a PR. Feel free to start your own just let me know, thanks!
from redux-beacon.
For those needing Global Site Tag support here are the steps you can follow as we wait for this to be added to Redux Beacon.
Step 1
Like with the Google Analytics target, the first step is to add the tracking snippet to the head of your single page app's index.html
file:
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());
gtag('config', 'GA_TRACKING_ID', { 'send_page_view': false });
</script>
gtag('config', 'GA_TRACKING_ID');
line from the tracking snippet provided by Google Analytics, and replace it with gtag('config', 'GA_TRACKING_ID', { 'send_page_view': false });
where GA_TRACKING_ID
is the one provided to you by Google Analytics.
Step 2
Next, copy & paste the following function wherever you are configuring Redux Beacon in your project.
function GoogleSiteTag(gaTrackingId) {
return function target(events) {
// Ensure the target works when doing SSR
if (typeof window === 'undefined') {
return;
}
// Ensure the Google Site Tag snippet is available
if (typeof window.gtag !== 'function') {
throw new Error('window.gtag is not a function. Did you forget to include the Google Site Tag snippet?');
}
// Push the events to Google Site Tag
events.forEach(event => {
if (event.type === 'page') {
gtag('config', gaTrackingId, event);
} else if (event.type === 'event') {
gtag('event', event.name, event);
}
});
};
}
Step 3
Then provide this function/target when creating the middleware or a meta reducer:
const gaTrackingId = 'My GA Tracking Id'; // <<< Replace with your tracking Id.
const middleware = createMiddleware(eventsMap, GoogleSiteTag(gaTrackingId));
const metaReducer = createMetaReducer(eventsMap, GoogleSiteTag(gaTrackingId));
Step 4
Finally, in your event definitions if you want to push a page view:
const pageView = (action) => ({
type: 'page',
page_title: 'whatever' // probably get this by mapping the route to a map of page titles
page_location: action.payload.location // or wherever this is in your action
page_path: action.payload.path // or wherever this is in your action
});
And, if you want to push an event:
const event = (action) => ({
type: 'event',
name: 'event_name', // You need this
'parameter_1': 'value_1',
'parameter_2': 'value_2',
});
Review
What we've done here is create a custom Redux Beacon target for Google Site Tag. It's a very bare-bones target that I hacked together on my lunch break. I'm leaning on y'all to help me test it out. I do intend to add a similar target to Redux Beacon in the next few days that is a little more robust and feature-rich. Until then, I hope this'll do.
- I would love a pull request that adds this target to Redux Beacon (with tests and support for multiple tracking Ids)
- I would also accept a pull request adding documentation around creating custom targets, for scenarios like these where Redux Beacon doesn't expose its own.
Happy analytics tracking 🙂
from redux-beacon.
Finally published! https://rangle.gitbook.io/redux-beacon/targets/googleanalyticsgtag
from redux-beacon.
Related Issues (20)
- Redux Beacon Google Tag Manager docu down HOT 2
- trackException() sending incorrect fields object HOT 2
- Support for react-native-google-analytics-bridge version 6 HOT 1
- How are we meant to test this? HOT 1
- [TypeScript] Add support for typings in EventDefinition HOT 3
- Documentation request: please remove the Github Pages docs HOT 3
- Documentation Bug: Broken links on readme.md HOT 1
- How to track external link when each link has its own metadata? HOT 3
- trackEvent eventDefinition not showing the correct parameters HOT 1
- Gtag, access user-id config inside redux-beacon, React HOT 3
- [Typescript] combineEvents forces invalid type HOT 1
- Error when trying to track e-commerce items in GA following documentation HOT 1
- Update docs for usage with React Native + Segment HOT 1
- Add Matomo (formerly Piwik) support HOT 2
- Integration with Redux Dynamic Modules HOT 1
- Distribute as ES module HOT 1
- IP anonymization with Google Analytics (gtag) HOT 2
- Any Event [*] is invoked for all events even though the exact key match present HOT 1
- @amplitude/analytics-browser support
- Offline storage doesn't persist events
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-beacon.