Skip to content

Commit

Permalink
Revert "Move "tracks" analytics into a shared calypso-analytics packa…
Browse files Browse the repository at this point in the history
…ge (#39001)" (#39304)

This reverts commit 2e3c19a.
  • Loading branch information
gwwar authored Feb 7, 2020
1 parent 2e3c19a commit cc55eee
Show file tree
Hide file tree
Showing 21 changed files with 311 additions and 788 deletions.
14 changes: 5 additions & 9 deletions client/lib/analytics/ad-tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@ import { loadScript } from '@automattic/load-script';
import {
isPiiUrl,
costToUSD,
doNotTrack,
getCurrentUser,
isAdTrackingAllowed,
mayWeTrackCurrentUserGdpr,
refreshCountryCodeCookieGdpr,
} from 'lib/analytics/utils';

import {
getTracksAnonymousUserId,
getCurrentUser,
getDoNotTrack,
} from '@automattic/calypso-analytics';

/**
* Module variables
*/
Expand Down Expand Up @@ -1446,7 +1442,7 @@ function floodlightSessionId() {
function floodlightUserParams() {
const params = {};
const currentUser = getCurrentUser();
const anonymousUserId = getTracksAnonymousUserId();
const anonymousUserId = tracksAnonymousUserId();

if ( currentUser ) {
params.u4 = currentUser.hashedPii.ID;
Expand Down Expand Up @@ -1711,15 +1707,15 @@ function setupWpcomFloodlightGtag() {
* 4. the current user could be in the GDPR zone and hasn't consented to tracking
* 5. `document.location.href` may contain personally identifiable information
*
* Note that getDoNotTrack() and isPiiUrl() can change at any time which is why we do not cache them.
* Note that doNotTrack() and isPiiUrl() can change at any time which is why we do not cache them.
*
* @returns {boolean} true if GA is allowed.
*/
export function isGoogleAnalyticsAllowed() {
return (
isGoogleAnalyticsEnabled &&
config.isEnabled( 'ad-tracking' ) &&
! getDoNotTrack() &&
! doNotTrack() &&
! isPiiUrl() &&
mayWeTrackCurrentUserGdpr()
);
Expand Down
45 changes: 44 additions & 1 deletion client/lib/analytics/docs/tracks.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,45 @@
Analytics: Tracks
=================

Moved to the [calypso-analytics package](../../../../packages/calypso-analytics/README.md)
Automatticians may refer to internal documentation for more information about Tracks.

## Usage

Note: In most situations it is best to use the [Analytics Middleware](https://github.com/Automattic/wp-calypso/tree/master/client/state/analytics), which has no direct browser dependencies and therefore will not complicate any unit testing of the modules where it is used.

### `recordGoogleEvent( name, properties )`

```js
import { recordTracksEvent } from 'state/analytics/actions';

dispatch( recordTracksEvent( 'calypso_checkout_coupon_apply', { 'coupon_code': 'abc123' } ) );
```

### `analytics.tracks.recordEvent( name, properties )` (Deprecated)

_Note: Unless you have a strong reason to call `analytics.tracks` directly, you should use the Analytics Middleware instead._

Record an event with optional properties:

```js
analytics.tracks.recordEvent( 'calypso_checkout_coupon_apply', {
'coupon_code': 'abc123'
} );
```

## Naming Conventions

To be recorded, event names originating from Calypso must be prefixed by `calypso_`, and each token in the event and property names must be separated by an underscore (`_`).

_Note: Events not prefixed by `calypso_`, with words not separated by underscore (e.g. by spaces or dashes), or written in camel case, **will be discarded**._

In order to keep similar events grouped together when sorted in an alphabetized list (as is typical with analytics tools), put the verb at _the end_ of the event name:

- `calypso_cart_product_add`
- `calypso_cart_product_remove`

If we had instead used `calypso_add_cart_product` and `calypso_remove_cart_product`, then they'd likely be separated in a list of all the event names.

Finally, for consistency, the verb at the end should be in a non-conjugated form like `add`, `remove`, `view`, or `click`, and _not_ `adds`, `added`, or `adding`.

With the exception of separating tokens with underscores, these rules do not apply to property names. `coupon_code` is perfectly fine.
5 changes: 2 additions & 3 deletions client/lib/analytics/hotjar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import debug from 'debug';
* Internal dependencies
*/
import config from 'config';
import { mayWeTrackCurrentUserGdpr, isPiiUrl } from './utils';
import { getDoNotTrack } from '@automattic/calypso-analytics';
import { mayWeTrackCurrentUserGdpr, doNotTrack, isPiiUrl } from './utils';
import { isE2ETest } from 'lib/e2e';

const hotjarDebug = debug( 'calypso:analytics:hotjar' );
Expand All @@ -20,7 +19,7 @@ export function addHotJarScript() {
hotJarScriptLoaded ||
! config( 'hotjar_enabled' ) ||
isE2ETest() ||
getDoNotTrack() ||
doNotTrack() ||
isPiiUrl() ||
! mayWeTrackCurrentUserGdpr()
) {
Expand Down
Loading

0 comments on commit cc55eee

Please sign in to comment.