-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API to decorate link with user/session info
- Loading branch information
Showing
6 changed files
with
379 additions
and
1 deletion.
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
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
47 changes: 47 additions & 0 deletions
47
Sources/Snowplow/Tracker/CrossDeviceParameterConfiguration.swift
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2013-2023 Snowplow Analytics Ltd. All rights reserved. | ||
// | ||
// This program is licensed to you under the Apache License Version 2.0, | ||
// and you may not use this file except in compliance with the Apache License | ||
// Version 2.0. You may obtain a copy of the Apache License Version 2.0 at | ||
// http://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the Apache License Version 2.0 is distributed on | ||
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the Apache License Version 2.0 for the specific | ||
// language governing permissions and limitations there under. | ||
|
||
import Foundation | ||
|
||
/// | ||
/// Configuration object for ``TrackerController/decorateLink`` | ||
/// | ||
/// Whether to include the following values when decorating a link: | ||
/// - `sessionId`: Value of ``SessionController.sessionId`` | ||
/// - `subjectUserId`: Value of ``Subject.userId`` | ||
/// - `sourceId`: Value of ``Tracker.appId`` | ||
/// - `platform`: Value of ``Tracker.platform`` | ||
/// - `reason`: Optional identifier/information for cross-navigation | ||
/// | ||
/// ``sourceId`` and ``sessionId`` are enabled by default. | ||
public class CrossDeviceParameterConfiguration : NSObject { | ||
var sessionId: Bool | ||
var subjectUserId: Bool | ||
var sourceId: Bool | ||
var sourcePlatform: Bool | ||
var reason: String? | ||
|
||
init( | ||
sessionId: Bool = true, | ||
subjectUserId: Bool = false, | ||
sourceId: Bool = true, | ||
sourcePlatform: Bool = false, | ||
reason: String? = nil | ||
) { | ||
self.sessionId = sessionId | ||
self.subjectUserId = subjectUserId | ||
self.sourceId = sourceId | ||
self.sourcePlatform = sourcePlatform | ||
self.reason = reason | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2013-2023 Snowplow Analytics Ltd. All rights reserved. | ||
// | ||
// This program is licensed to you under the Apache License Version 2.0, | ||
// and you may not use this file except in compliance with the Apache License | ||
// Version 2.0. You may obtain a copy of the Apache License Version 2.0 at | ||
// http://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the Apache License Version 2.0 is distributed on | ||
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the Apache License Version 2.0 for the specific | ||
// language governing permissions and limitations there under. | ||
|
||
import Foundation | ||
|
||
public extension String { | ||
func toBase64(urlSafe: Bool = true) -> String { | ||
var encoded = Data(self.utf8).base64EncodedString() | ||
if urlSafe { | ||
// We need URL safe with no padding. Since there is no built-in way to do this, we transform | ||
// the encoded payload to make it URL safe by replacing chars that are different in the URL-safe | ||
// alphabet. Namely, 62 is - instead of +, and 63 _ instead of /. | ||
// See: https://tools.ietf.org/html/rfc4648#section-5 | ||
encoded = encoded | ||
.replacingOccurrences(of: "/", with: "_") | ||
.replacingOccurrences(of: "+", with: "-") | ||
|
||
// There is also no padding since the length is implicitly known. | ||
encoded = encoded.trimmingCharacters(in: CharacterSet(charactersIn: "=")) | ||
} | ||
return encoded | ||
} | ||
} |
Oops, something went wrong.