@tapfiliate/tapfiliate-js 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2021 Tapfiliate
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Tapfiliate npm module
2
2
 
3
- This is a simple wrapper for the Tapfiliate [JavaScript integration](https://tapfiliate.com/docs/javascript/) library to help with implementation in modern frontend applications.
3
+ This is a simple wrapper for the Tapfiliate [JavaScript integration](https://developers.tapfiliate.com/tracking/javascript) library to help with implementation in modern frontend applications.
4
4
 
5
5
  ### Table of content
6
6
 
@@ -33,7 +33,7 @@ Read more about testing your integration [here](https://support.tapfiliate.com/e
33
33
 
34
34
  ## API
35
35
 
36
- This npm module mirrors the Tapfiliate [JavaScript integration](https://tapfiliate.com/docs/javascript/) library and all functions from the Javascript Docs can be used with this wrapper with the only difference that the first parameter is now the function name.
36
+ This npm module mirrors the Tapfiliate [JavaScript integration](https://developers.tapfiliate.com/tracking/javascript) library and all functions from the Javascript Docs can be used with this wrapper with the only difference that the first parameter is now the function name.
37
37
 
38
38
  e.g. instead of:
39
39
  `tap('conversion', external id, amount, options, commission type, callback);`
@@ -63,4 +63,13 @@ To make the initialization easier we added the init function. Use Tap.init to in
63
63
  | cookie_domain | `string`. Explicitly define the domain to place the cookie on. Can be used when users land on subdomain A and later convert on subdomain B. |
64
64
  | referral_code | `String` Use this to explicitly pass a specific referral code for this click. |
65
65
  | referral_code_param | `String`. Use an alternative query parameter for the referral code, instead of ref. For example if you would like your links to look like: https://.../?via=, pass via |
66
- | always_callback | `Boolean` Set to true to also make your callback fire on failed tracking attempts. [More info](https://tapfiliate.com/docs/javascript/#detect-callback) |
66
+ | always_callback | `Boolean` Set to true to also make your callback fire on failed tracking attempts. [More info](https://developers.tapfiliate.com/tracking/javascript#callbacks) |
67
+
68
+ ## Changelog
69
+
70
+ ### 1.0.3
71
+
72
+ - Works with `require()` and in server-side rendering. The package now ships both CommonJS and ES module builds, which fixes `SyntaxError: Unexpected token 'export'` in Next.js and Node.js 18–20 ([#1](https://github.com/tapfiliate/tapfiliate-js/issues/1)).
73
+ - TypeScript types included.
74
+ - `Tap` is no longer mistaken for a promise or a transpiled module by bundlers.
75
+ - If tapfiliate.js fails to load (for example, blocked by an ad blocker), a console warning names the script.
package/dist/index.cjs ADDED
@@ -0,0 +1,47 @@
1
+ // Names that JavaScript itself and module loaders probe on any object. Forwarding them as tapfiliate.js
2
+ // methods made Tap look like a promise (`then`) or like a transpiled ES module (`__esModule`).
3
+ const notTapMethods = new Set(["then", "__esModule", "toJSON", "constructor"]);
4
+
5
+ const handler = {
6
+ get: function(target, name) {
7
+ if (Object.prototype.hasOwnProperty.call(target, name)) return target[name];
8
+ if (typeof name !== "string" || notTapMethods.has(name)) return undefined;
9
+ return (...args) => {
10
+ window.__tap(name, ...args);
11
+ };
12
+ }
13
+ };
14
+
15
+ const target = {
16
+ init: (accountId, createOptions = { integration: "npm-module" }, createCallback, detectOptions = {}, detectCallback) => {
17
+ if (window.__tap) return;
18
+
19
+ (function(t, a, p) {
20
+ t.TapfiliateObject = a;
21
+ t[a] = t[a] || function() {
22
+ (t[a].q = t[a].q || []).push(arguments);
23
+ };
24
+ })(window, "__tap");
25
+
26
+ var script = document.createElement("script");
27
+ script.src = "https://script.tapfiliate.com/tapfiliate.js";
28
+ script.type = "text/javascript";
29
+ script.async = true;
30
+
31
+ document.getElementsByTagName("head")[0].appendChild(script);
32
+
33
+ // Ad blockers routinely block the script. 1.0.2 stayed silent; an uncaught error here would flood
34
+ // every site's error monitoring once ^1.0.2 picks up this version, so it is a warning.
35
+ script.addEventListener("error", function() {
36
+ console.warn(`${this.src} failed to load.`);
37
+ });
38
+
39
+ window.__tap("create", accountId, createOptions, createCallback);
40
+ window.__tap("detect", detectOptions, detectCallback);
41
+ }
42
+ };
43
+
44
+ var Tap = new Proxy(target, handler);
45
+
46
+ module.exports = Tap;
47
+ module.exports.default = Tap;
@@ -0,0 +1,20 @@
1
+ export interface TapCreateOptions {
2
+ integration?: string;
3
+ [option: string]: unknown;
4
+ }
5
+
6
+ export interface Tap {
7
+ /** Loads tapfiliate.js once, then runs `create` and `detect`. */
8
+ init(
9
+ accountId: string,
10
+ createOptions?: TapCreateOptions,
11
+ createCallback?: (...args: unknown[]) => void,
12
+ detectOptions?: Record<string, unknown>,
13
+ detectCallback?: (...args: unknown[]) => void
14
+ ): void;
15
+ /** Any other tapfiliate.js method, e.g. Tap.conversion(id, amount) or Tap.customer(id). */
16
+ [method: string]: (...args: any[]) => void;
17
+ }
18
+
19
+ declare const Tap: Tap;
20
+ export default Tap;
package/dist/index.mjs ADDED
@@ -0,0 +1,46 @@
1
+ // Names that JavaScript itself and module loaders probe on any object. Forwarding them as tapfiliate.js
2
+ // methods made Tap look like a promise (`then`) or like a transpiled ES module (`__esModule`).
3
+ const notTapMethods = new Set(["then", "__esModule", "toJSON", "constructor"]);
4
+
5
+ const handler = {
6
+ get: function(target, name) {
7
+ if (Object.prototype.hasOwnProperty.call(target, name)) return target[name];
8
+ if (typeof name !== "string" || notTapMethods.has(name)) return undefined;
9
+ return (...args) => {
10
+ window.__tap(name, ...args);
11
+ };
12
+ }
13
+ };
14
+
15
+ const target = {
16
+ init: (accountId, createOptions = { integration: "npm-module" }, createCallback, detectOptions = {}, detectCallback) => {
17
+ if (window.__tap) return;
18
+
19
+ (function(t, a, p) {
20
+ t.TapfiliateObject = a;
21
+ t[a] = t[a] || function() {
22
+ (t[a].q = t[a].q || []).push(arguments);
23
+ };
24
+ })(window, "__tap");
25
+
26
+ var script = document.createElement("script");
27
+ script.src = "https://script.tapfiliate.com/tapfiliate.js";
28
+ script.type = "text/javascript";
29
+ script.async = true;
30
+
31
+ document.getElementsByTagName("head")[0].appendChild(script);
32
+
33
+ // Ad blockers routinely block the script. 1.0.2 stayed silent; an uncaught error here would flood
34
+ // every site's error monitoring once ^1.0.2 picks up this version, so it is a warning.
35
+ script.addEventListener("error", function() {
36
+ console.warn(`${this.src} failed to load.`);
37
+ });
38
+
39
+ window.__tap("create", accountId, createOptions, createCallback);
40
+ window.__tap("detect", detectOptions, detectCallback);
41
+ }
42
+ };
43
+
44
+ var Tap = new Proxy(target, handler);
45
+
46
+ export default Tap;
package/package.json CHANGED
@@ -1,19 +1,43 @@
1
1
  {
2
2
  "name": "@tapfiliate/tapfiliate-js",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Simple wrapper for the Tapfiliate javascript integration library to help with implementation in modern frontend applications.",
5
- "main": "index.js",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.cjs",
13
+ "default": "./dist/index.mjs"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "sideEffects": false,
6
21
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
22
+ "build": "node scripts/build.mjs",
23
+ "test": "npm run build && node --test test/*.test.mjs",
24
+ "prepublishOnly": "npm test"
8
25
  },
9
- "author": "",
26
+ "keywords": [
27
+ "tapfiliate",
28
+ "affiliate",
29
+ "affiliate-tracking",
30
+ "referral",
31
+ "conversion-tracking"
32
+ ],
33
+ "author": "Tapfiliate",
10
34
  "license": "ISC",
11
35
  "repository": {
12
36
  "type": "git",
13
- "url": "git+https://github.com/Tapfiliate/tapfiliate-js.git"
37
+ "url": "git+https://github.com/tapfiliate/tapfiliate-js.git"
14
38
  },
15
- "homepage": "https://github.com/Tapfiliate/tapfiliate-js#readme",
39
+ "homepage": "https://developers.tapfiliate.com/tracking/javascript",
16
40
  "bugs": {
17
- "url": "https://github.com/Tapfiliate/tapfiliate-js/issues"
41
+ "url": "https://github.com/tapfiliate/tapfiliate-js/issues"
18
42
  }
19
43
  }
package/index.js DELETED
@@ -1,46 +0,0 @@
1
- const handler = {
2
- get: function (target, name) {
3
- return target.hasOwnProperty(name)
4
- ? target[name]
5
- : (...args) => {
6
- window.__tap(name, ...args);
7
- };
8
- }
9
- };
10
-
11
- const target = {
12
- init: (
13
- accountId,
14
- createOptions = { integration: "npm-module" },
15
- createCallback,
16
- detectOptions = {},
17
- detectCallback
18
- ) => {
19
- if (window.__tap) return;
20
-
21
- (function (t, a, p) {
22
- t.TapfiliateObject = a;
23
- t[a] =
24
- t[a] ||
25
- function () {
26
- (t[a].q = t[a].q || []).push(arguments);
27
- };
28
- })(window, "__tap");
29
-
30
- var script = document.createElement("script");
31
- script.src = "https://script.tapfiliate.com/tapfiliate.js";
32
- script.type = "text/javascript";
33
- script.async = true;
34
-
35
- document.getElementsByTagName("head")[0].appendChild(script);
36
- script.addEventListener("error", () => {
37
- new Error(`${this.src} failed to load.`);
38
- });
39
-
40
- window.__tap("create", accountId, createOptions, createCallback);
41
- window.__tap("detect", detectOptions, detectCallback);
42
- }
43
- };
44
- var Tap = new Proxy(target, handler);
45
-
46
- export default Tap;