-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improve the types and exports This should make the package a lot easier to use in other projects. ### Added - An index.js that exports everything from the package - Compiled javascript in the published package - Separate type definitions in the published package ### Changed - The middlewares are now functions instead of objects with methods - The attribution models are now functions instead of objects with methods
- Loading branch information
1 parent
3f04fe2
commit 2524f6d
Showing
31 changed files
with
185 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ coverage/ | |
|
||
.npmrc | ||
package-lock.json | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
import { AttributionModel, Interaction } from '../../types'; | ||
import { AttributionModel, Interaction } from '../types'; | ||
|
||
/** | ||
* This implements the "first interaction" attribution model | ||
* which simply returns the first interaction | ||
* | ||
* Since only one interaction is returned, it is not weighted | ||
*/ | ||
export default class FirstInteraction implements AttributionModel { | ||
public attribute(interactions: Interaction[]): Interaction { | ||
if (interactions.length === 0) { | ||
return null; | ||
} | ||
const firstInteraction: AttributionModel = (interactions: Interaction[]): Interaction => { | ||
if (interactions.length === 0) { | ||
return null; | ||
} | ||
|
||
const filteredInteractions = interactions.filter((interaction) => !interaction.excluded); | ||
const filteredInteractions = interactions.filter((interaction) => !interaction.excluded); | ||
|
||
// If all we had were excluded interactions we return the first one as it's better than nothing | ||
return filteredInteractions.shift() || interactions.shift(); | ||
} | ||
// If all we had were excluded interactions we return the first one as it's better than nothing | ||
return filteredInteractions.shift() || interactions.shift(); | ||
} | ||
|
||
export default firstInteraction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import { AttributionModel, Interaction } from '../../types'; | ||
import { AttributionModel, Interaction } from '../types'; | ||
|
||
/** | ||
* This implements the "last interaction" attribution model | ||
* which simply returns the last interaction | ||
* | ||
* Since only one interaction is returned, it is not weighted | ||
*/ | ||
export default class LastInteraction implements AttributionModel { | ||
public attribute(interactions: Interaction[]): Interaction { | ||
const includedInteractions = interactions.filter((interaction) => !interaction.excluded); | ||
const lastInteraction: AttributionModel = (interactions: Interaction[]): Interaction => { | ||
const includedInteractions = interactions.filter((interaction) => !interaction.excluded); | ||
|
||
// Interactions are logged in order of occurrence, so we simply need to return the last one | ||
return includedInteractions.pop() ?? null; | ||
} | ||
// Interactions are logged in order of occurrence, so we simply need to return the last one | ||
return includedInteractions.pop() ?? null; | ||
} | ||
|
||
export default lastInteraction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
import { AttributionModel, Interaction, WeightedInteraction } from '../../types'; | ||
import { AttributionModel, Interaction, WeightedInteraction } from '../types'; | ||
|
||
/** | ||
* This implements the "linear" attribution model | ||
* which equally distributes the attribution over all interactions | ||
*/ | ||
export default class Linear implements AttributionModel { | ||
public attribute(interactions: Interaction[]): WeightedInteraction[] { | ||
if (interactions.length === 0) { | ||
return []; | ||
} | ||
|
||
let includedInteractions = interactions.filter((interaction) => !interaction.excluded) | ||
const linear: AttributionModel = (interactions: Interaction[]): WeightedInteraction[] => { | ||
if (interactions.length === 0) { | ||
return []; | ||
} | ||
|
||
// If all our interactions are excluded, ignore the exclusions anyway | ||
if (includedInteractions.length === 0) { | ||
includedInteractions = interactions; | ||
} | ||
let includedInteractions = interactions.filter((interaction) => !interaction.excluded) | ||
|
||
return includedInteractions.map((interaction) => { | ||
return { | ||
...interaction, | ||
weight: 1 / includedInteractions.length, | ||
} | ||
}); | ||
// If all our interactions are excluded, ignore the exclusions anyway | ||
if (includedInteractions.length === 0) { | ||
includedInteractions = interactions; | ||
} | ||
|
||
return includedInteractions.map((interaction) => { | ||
return { | ||
...interaction, | ||
weight: 1 / includedInteractions.length, | ||
} | ||
}); | ||
} | ||
|
||
export default linear; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.