Skip to content

Instantly share code, notes, and snippets.

View tiagogm's full-sized avatar

Tiago Morais tiagogm

View GitHub Profile
//in a common use case, button click.
<button data-event-name="search-show-more-results" data-event-params="{currentPage: 4}"/> Sow more </button>
//when someone toggle a select dropdown
<select data-event-name="search-show-access-filters">
..
</select>
//when someone interacts with a custom component
<UserProfile>
const pushEvent = (event: IEvent) = {
if (typeof window === 'undefined' || !window.dataLayer) {
return;
}
window.dataLayer.push( event: event.name, ...event.properties });
}
export const GTM = {
pushEvent
const pushEvent = (event: IEvent) => {
if (typeof window === 'undefined' || !(window as any).dataLayer) {
return;
}
window.dataLayer.push({ event: event.name, ...event.properties });
};
export const gtm = {
pushEvent
//somewhere in the code
analyticsService.trackEvent(SEARCH_EVENTS.datedSearch, { checkIn, checkOut });
//configuration of all events from multiple root level pages
const eventsRegister = {
...SEARCH_EVENTS_CONFIG,
...LISTING_EVENTS_CONFIG
//loads more
}
// for example, in `src/views/search/events.ts` file
export const SEARCH_EVENTS_CONFIG: EventConfigMap = {
[SEARCH_EVENTS.datedSearch]: [evtCh.GA, evtCh.KSM, evtCh.FB],
//in on page
window.uetq.push({ 'ec': 'listing', 'ea': 'contacted-host', 'ev': 1 });
_kmq.push(['record', 'contact host', { 'user_id': 'UserId' }]);
//in another page
Scenestealer.trackRequestBooking(`${booking.listingId}`);
utils.addGoogleAnalyticsEvent('listing', 'reques-booking', '', 1);
utils.recordFacebookEvent('track', 'Lead', { content_name: 'request booking', user_id: 'UserId' });
utils.recordFacebookEvent('trackCustom', 'lead',{ action: 'request booking'});
@tiagogm
tiagogm / Timer.js
Created April 8, 2017 19:17 — forked from theprojectsomething/Timer.js
Timer - a simple JS timing implementation utilising requestAnimationFrame.
/*
Timer
- utilises animation frames (with a fallback to setTimeout when using the polyfill, below)
- returns remaining (or running) time
- pass a callback [fn], with an optional duration [ms] and autotart [bool], to the constructor or 'init' method
eg. new Timer(foo, 1000) *or* (new Timer()).init(foo, 0, true)
- for uniform x-browser support combine with the requestAnimationFrame polyfill from Erik Möller, et. al.
[https://github.com/darius/requestAnimationFrame]
*/
import {logger} from 'shared/components/utilities/logger';
export function withSpinner(target, key, descriptor) {
let ptr = descriptor.value;
descriptor.value = function(...args) {
if (this.spinner) {
this.spinner.setLoading(true);
}
return ptr.apply(this, args)
.then(() => {