Skip to content

Commit

Permalink
add option for 'createAlias' for not calling identify
Browse files Browse the repository at this point in the history
  • Loading branch information
zihejia committed Jun 25, 2022
1 parent 763b116 commit 7c6d58e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,16 @@
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
launchAutomaticallySubstyle = "8">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/MixpanelDemo">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "86F86E8A22440C5C00B69832"
BuildableName = "MixpanelDemoWatch.app"
BlueprintName = "MixpanelDemoWatch"
ReferencedContainer = "container:MixpanelDemo.xcodeproj">
</BuildableReference>
</RemoteRunnable>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand All @@ -75,27 +73,16 @@
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
launchAutomaticallySubstyle = "8">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/MixpanelDemo">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "86F86E8A22440C5C00B69832"
BuildableName = "MixpanelDemoWatch.app"
BlueprintName = "MixpanelDemoWatch"
ReferencedContainer = "container:MixpanelDemo.xcodeproj">
</BuildableReference>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "86F86E8A22440C5C00B69832"
BuildableName = "MixpanelDemoWatch.app"
BlueprintName = "MixpanelDemoWatch"
ReferencedContainer = "container:MixpanelDemo.xcodeproj">
</BuildableReference>
</MacroExpansion>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,46 +54,33 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/MixpanelDemo">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "86F86E8A22440C5C00B69832"
BuildableName = "MixpanelDemoWatch.app"
BlueprintName = "MixpanelDemoWatch"
ReferencedContainer = "container:MixpanelDemo.xcodeproj">
</BuildableReference>
</RemoteRunnable>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/MixpanelDemo">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "86F86E8A22440C5C00B69832"
BuildableName = "MixpanelDemoWatch.app"
BlueprintName = "MixpanelDemoWatch"
ReferencedContainer = "container:MixpanelDemo.xcodeproj">
</BuildableReference>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "86F86E8A22440C5C00B69832"
BuildableName = "MixpanelDemoWatch.app"
BlueprintName = "MixpanelDemoWatch"
ReferencedContainer = "container:MixpanelDemo.xcodeproj">
</BuildableReference>
</MacroExpansion>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
11 changes: 9 additions & 2 deletions Sources/MixpanelInstance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,9 @@ extension MixpanelInstance {
The alias method creates an alias which Mixpanel will use to remap one id to another.
Multiple aliases can point to the same identifier.

Please note: With Mixpanel Identity Merge enabled, calling alias is no longer required
but can be used to merge two IDs in scenarios where identify() would fail


`mixpanelInstance.createAlias("New ID", distinctId: mixpanelInstance.distinctId)`

Expand All @@ -663,10 +666,12 @@ extension MixpanelInstance {
- parameter alias: A unique identifier that you want to use as an identifier for this user.
- parameter distinctId: The current user identifier.
- parameter usePeople: boolean that controls whether or not to set the people distinctId to the event distinctId.
- parameter andIdentify: an optional boolean that controls whether or not to call 'identify' with your current
user identifier(not alias). Default to true for keeping your signup funnels working correctly in most cases.
- parameter completion: an optional completion handler for when the createAlias has completed.
This should only be set to false if you wish to prevent people profile updates for that user.
*/
open func createAlias(_ alias: String, distinctId: String, usePeople: Bool = true, completion: (() -> Void)? = nil) {
open func createAlias(_ alias: String, distinctId: String, usePeople: Bool = true, andIdentify: Bool = true, completion: (() -> Void)? = nil) {
if hasOptedOutTracking() {
if let completion = completion {
DispatchQueue.main.async(execute: completion)
Expand Down Expand Up @@ -731,7 +736,9 @@ extension MixpanelInstance {

let properties = ["distinct_id": distinctId, "alias": alias]
track(event: "$create_alias", properties: properties)
identify(distinctId: distinctId, usePeople: usePeople)
if andIdentify {
identify(distinctId: distinctId, usePeople: usePeople)
}
flush(completion: completion)
} else {
Logger.error(message: "alias: \(alias) matches distinctId: \(distinctId) - skipping api call.")
Expand Down

0 comments on commit 7c6d58e

Please sign in to comment.