Skip to content

Implement analytics-compat package #4460

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

Merged
merged 8 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"firebase-firestore-integration-test",
"firebase-messaging-integration-test",
"@firebase/app-exp",
"@firebase/analytics-compat",
"@firebase/analytics-exp",
"@firebase/auth-exp",
"@firebase/auth-compat",
Expand Down
2 changes: 1 addition & 1 deletion common/api-review/analytics-exp.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type CustomEventName<T> = T extends EventNameString ? never : T;
// @public
export interface CustomParams {
// (undocumented)
[key: string]: any;
[key: string]: unknown;
}

// @public
Expand Down
33 changes: 33 additions & 0 deletions packages-exp/analytics-compat/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const path = require('path');

module.exports = {
'extends': '../../config/.eslintrc.js',
'parserOptions': {
'project': 'tsconfig.json',
'tsconfigRootDir': __dirname
},
rules: {
'import/no-extraneous-dependencies': [
'error',
{
'packageDir': [path.resolve(__dirname, '../../'), __dirname]
}
]
}
};
32 changes: 32 additions & 0 deletions packages-exp/analytics-compat/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// eslint-disable-next-line @typescript-eslint/no-require-imports
const karmaBase = require('../../config/karma.base');

const files = [`**/*.test.ts`];

module.exports = function (config) {
config.set({
...karmaBase,
files,
preprocessors: { '**/*.ts': ['webpack', 'sourcemap'] },
frameworks: ['mocha']
});
};

module.exports.files = files;
57 changes: 57 additions & 0 deletions packages-exp/analytics-compat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "@firebase/analytics-compat",
"version": "0.0.900",
"description": "",
"private": true,
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"main": "dist/index.cjs.js",
"browser": "dist/index.esm.js",
"module": "dist/index.esm.js",
"esm2017": "dist/index.esm2017.js",
"files": ["dist"],
"license": "Apache-2.0",
"peerDependencies": {
"@firebase/app-compat": "0.x"
},
"devDependencies": {
"@firebase/app-compat": "0.0.900",
"rollup": "2.35.1",
"@rollup/plugin-json": "4.1.0",
"rollup-plugin-typescript2": "0.29.0",
"typescript": "4.0.5"
},
"repository": {
"directory": "packages-exp/analytics-compat",
"type": "git",
"url": "https://github.com/firebase/firebase-js-sdk.git"
},
"bugs": {
"url": "https://github.com/firebase/firebase-js-sdk/issues"
},
"scripts": {
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
"build": "rollup -c",
"build:deps": "lerna run --scope @firebase/analytics-compat --include-dependencies build",
"build:release": "rollup -c rollup.config.release.js",
"dev": "rollup -c -w",
"test": "run-p lint test:browser",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:browser",
"test:browser": "karma start --single-run",
"test:browser:debug": "karma start --browsers=Chrome --auto-watch"
},
"typings": "dist/analytics-compat-public.d.ts",
"dependencies": {
"@firebase/component": "0.2.0",
"@firebase/analytics-exp": "0.0.900",
"@firebase/analytics-types": "0.4.0",
"@firebase/util": "0.3.4",
"tslib": "^1.11.1"
},
"nyc": {
"extension": [
".ts"
],
"reportDir": "./coverage/node"
}
}
58 changes: 58 additions & 0 deletions packages-exp/analytics-compat/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import json from '@rollup/plugin-json';
import typescriptPlugin from 'rollup-plugin-typescript2';
import typescript from 'typescript';
import { es2017BuildsNoPlugin, es5BuildsNoPlugin } from './rollup.shared';

/**
* ES5 Builds
*/
const es5BuildPlugins = [
typescriptPlugin({
typescript
}),
json()
];

const es5Builds = es5BuildsNoPlugin.map(build => ({
...build,
plugins: es5BuildPlugins
}));

/**
* ES2017 Builds
*/
const es2017BuildPlugins = [
typescriptPlugin({
typescript,
tsconfigOverride: {
compilerOptions: {
target: 'es2017'
}
}
}),
json({ preferConst: true })
];

const es2017Builds = es2017BuildsNoPlugin.map(build => ({
...build,
plugins: es2017BuildPlugins
}));

export default [...es5Builds, ...es2017Builds];
73 changes: 73 additions & 0 deletions packages-exp/analytics-compat/rollup.config.release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import typescriptPlugin from 'rollup-plugin-typescript2';
import typescript from 'typescript';
import json from '@rollup/plugin-json';
import { importPathTransformer } from '../../scripts/exp/ts-transform-import-path';
import { es2017BuildsNoPlugin, es5BuildsNoPlugin } from './rollup.shared';

/**
* ES5 Builds
*/
const es5BuildPlugins = [
typescriptPlugin({
typescript,
clean: true,
abortOnError: false,
transformers: [importPathTransformer]
}),
json()
];

const es5Builds = es5BuildsNoPlugin.map(build => ({
...build,
plugins: es5BuildPlugins,
treeshake: {
moduleSideEffects: id => id === '@firebase/installations'
}
}));

/**
* ES2017 Builds
*/
const es2017BuildPlugins = [
typescriptPlugin({
typescript,
tsconfigOverride: {
compilerOptions: {
target: 'es2017'
}
},
abortOnError: false,
clean: true,
transformers: [importPathTransformer]
}),
json({
preferConst: true
})
];

const es2017Builds = es2017BuildsNoPlugin.map(build => ({
...build,
plugins: es2017BuildPlugins,
treeshake: {
moduleSideEffects: id => id === '@firebase/installations'
}
}));

export default [...es5Builds, ...es2017Builds];
53 changes: 53 additions & 0 deletions packages-exp/analytics-compat/rollup.shared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import pkg from './package.json';

const deps = Object.keys(
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
);

export const es5BuildsNoPlugin = [
/**
* Browser Builds
*/
{
input: 'src/index.ts',
output: [
{ file: pkg.main, format: 'cjs', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true }
],
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];

/**
* ES2017 Builds
*/
export const es2017BuildsNoPlugin = [
{
/**
* Browser Build
*/
input: 'src/index.ts',
output: {
file: pkg.esm2017,
format: 'es',
sourcemap: true
},
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];
56 changes: 56 additions & 0 deletions packages-exp/analytics-compat/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Officially recommended event names for gtag.js
* Any other string is also allowed.
*/
export enum EventName {
ADD_SHIPPING_INFO = 'add_shipping_info',
ADD_PAYMENT_INFO = 'add_payment_info',
ADD_TO_CART = 'add_to_cart',
ADD_TO_WISHLIST = 'add_to_wishlist',
BEGIN_CHECKOUT = 'begin_checkout',
/**
* @deprecated
* This event name is deprecated and is unsupported in updated
* Enhanced Ecommerce reports.
*/
CHECKOUT_PROGRESS = 'checkout_progress',
EXCEPTION = 'exception',
GENERATE_LEAD = 'generate_lead',
LOGIN = 'login',
PAGE_VIEW = 'page_view',
PURCHASE = 'purchase',
REFUND = 'refund',
REMOVE_FROM_CART = 'remove_from_cart',
SCREEN_VIEW = 'screen_view',
SEARCH = 'search',
SELECT_CONTENT = 'select_content',
SELECT_ITEM = 'select_item',
SELECT_PROMOTION = 'select_promotion',
/** @deprecated */
SET_CHECKOUT_OPTION = 'set_checkout_option',
SHARE = 'share',
SIGN_UP = 'sign_up',
TIMING_COMPLETE = 'timing_complete',
VIEW_CART = 'view_cart',
VIEW_ITEM = 'view_item',
VIEW_ITEM_LIST = 'view_item_list',
VIEW_PROMOTION = 'view_promotion',
VIEW_SEARCH_RESULTS = 'view_search_results'
}
Loading